C++ 逐行读取文件最小示例

此最小示例使用 std::getline 逐行读取文件并在 stdout 上打印每行。

read_file_line_by_line.cpp
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char** argv) {
    ifstream fin("test.tsv");
    string line;
    while (getline(fin, line)) {
        // TODO 你的代码放在这里。这只是一个示例!
        cout << line << endl;
    }
    fin.close();
}

Check out similar posts by category: C/C++