【发布时间】:2013-12-20 09:16:12
【问题描述】:
我有一个这样设置的输入文件:
Hello there
1 4
Goodbye now
4.9 3
我尝试这样读取数据:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
ifstream input("file.txt");
string name;
double num1, num2;
while(!input.eof()){
getline(input, name);
input >> num1;
input >> num2;
cout << name << endl;
cout << num1 << " " << num2 << endl;
}
}
但读取似乎失败了。有人可以帮我吗?
【问题讨论】:
-
getline没有从流中删除\n -
首选
"\n"而不是std::endl,除非你有理由刷新。
标签: c++