-
Two questions in C++
What would be the easiest way to output text to the console from a file?
If the file was this:
This is
the
file I am reading
cout should print that to the console. Is there an echo command? or would I use getline?
Also, how can I accept a file from the command prompt?
Code:
cout << "Enter a filename";
cin >> file;
ifstream inFile;
inFile.open(file);
does not work.
-
you opened the file but didnt do anything with it you can retrieve data from the file via ifstream through various methods such as:
string temp;
inFile >> temp
or getline(inFile, temp)
a simple google search of ifstream or c++ file io should give clear help
as far as accepting from command prompt, you just use command line parameters. The very first search result of this gave an example of reading a file using a command line argument
-
Yes, I figured out what I had to do and realized these were pretty n00bish questions. Oh well.