使用getline()函数可实现逐行读取:
ifstream in(argv[1]);
if (!in.is_open())
cout << "Error" << endl;
else
{
string buf;
while (!in.eof())
{
getline(in, buf);
cout<<buf<<endl;
}
}