C++逐行读取文件
1 分钟能读完
使用ifstream。
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream ifs("test.txt");
// 是否读取成功
if ( !ifs )
{
cout << "读取失败" << endl;
return 0;
}
string line;
while ( getline(ifs, line) )
cout << line << endl;
return 0;
}
这篇在全部 101 篇里的位置: