c++/逐行讀取txt檔案
阿新 • • 發佈:2018-12-18
#include <fstream> #include <string> #include <iostream> using namespace std;
int main() { ifstream in("1.txt"); ///string filename; string line;
if (in) // 有該檔案 { while (getline(in, line)) // line中不包括每行的換行符 { cout << line << endl; } } else // 沒有該檔案 { cout << "no such file" << endl; }
return 0; }