#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
if (argc < 2)
{
cout << "Usage: " << argv[0] << " filename.txt" << endl;
return -1;
}
ifstream ifs(argv[1]);
if (ifs.fail())
{
cout << "open " << argv[1] << " failed" << endl;
return -2;
}
while (true)
{
string line;
getline(ifs, line);
if (!ifs.eof())
cout << line << endl;
else
break;
}
ifs.close();
return 0;
}
温馨提示:答案为网友推荐,仅供参考