I'm currently writing a program that reads from a file, I have it decide what file to open and parse with this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
cout << "What file would you like to use?" << endl;
cin >> str;
ifstream fin(str);
while (fin >> str)
{
istringstream(str) >> num;
n++;
if (n == 1){ intr = num; }
if (n == 2){ roads = num; }
if (n >= 3)
numbs.push_back(num);
}
fin.close();
However I need to have the program work when using this in the command prompt:
.\program < myfile.txt
I have no ideal how to do this, my searches on google brought me to pages on the standard input library and functions that still require the filename in the parameters. Is there away to do this through fstream still? Any help is appreciated, its frustrating having what is usually easy for me holding my progress back entirely.
I'm using Visual Studio 2013 on a windows 7 machine.
You probably don't have to do anything. .\program < myfile.txt will run the program like normal with the only difference that cin will read the input from the file myfile.txt instead of from the user.