I need to get very basic input from an external file in C++. I tried searching the internet a few times but nothing really applied to what I need. This would be a .txt file that
Aside from the other suggestions, you can simply redirect a file to standard input, like so (where $
is the command prompt):
$ myprogram < mytextfile.txt
That will run myprogram
just as normal but take input from mytextfile.txt
as if you had typed it in. No need to adjust your own program at all.
(This works on both Unix/Linux systems and on Windows.)