我想逐行读取文件。做了类似的事情
void Parse (string filepath) {
ifstream sourceFile;
sourceFile.open(filepath);
for (string line; getline(sourceFile, line);) {
cout << "1" << endl;
cout << line << endl;
}
}
int main() {
Parse("C:\\test.txt");
getchar();
return 0;
}
然后将一些文本放入C:\test.txt
,但是当我运行时,我什么也没有得到。为什么?甚至不是“1”。如果文件也不存在,我注意到没有例外。我想这是一个问题的迹象?