【发布时间】:2020-08-15 20:51:14
【问题描述】:
我想读取一个 txt 文件,我想一个一个地处理行上的每个数字,应用一些函数并传递到另一行。当行结束时,我不知道如何对下面的行应用相同的操作。方法将从每一行得到不同的输出,这就是我必须分别处理每一行的原因。
int number;
ifstream readingFile("a.txt");
while(readingFile >> number){
/* Methods will be applied to each number in the line */
}
readingFile.close();
一个.txt
23 4 555
2123 44 21 4
1 45 667 2 112
【问题讨论】:
-
用 std::getline() 将整行读入 std::string 然后使用 istringstream 从字符串中取出数字。
标签: c++ methods while-loop line ifstream