Entry
Does anybody know how to open a text file and evaluate one line at a time?
Mar 18th, 2004 18:36
Aaron Hawley, Chris Ollar, http://www.research.att.com/~bs/bs_faq2.html#read-string
#include <iostream>
#include <fstream>
#include <string>
int main(int argc, char **argv)
{
if (argc != 2)
{
cout << "You need to specify one file" << endl;
}
else
{
char *filename = argv[1];
cout << "Your file: " << filename << endl;
ifstream infile(filename);
string one_line;
while(getline(infile, one_line)) {
cout << "Your line: " << one_line << endl;
}
}
}