【发布时间】:2014-06-09 20:30:30
【问题描述】:
我想知道在使用fstream 打开文件时如何跳过行。当我打开文件时,它会返回所有聚集在一起的数字,例如“201051535402530”
这是我的代码。
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string testing;
ifstream myfile;
myfile.open ("inputfile");
while (!myfile.eof())
{
getline(myfile, testing);
cout << testing;
}
return 0;
}
输入文件被列为:
20
10
5
15
35
40
25
30
【问题讨论】:
-
将
cout << testing;更改为cout << testing << " "; -
或
cout << testing << "\n";在单独的行上打印每个项目。 -
还有,谁教
while (!eof)?错了。