【发布时间】:2014-02-04 09:27:45
【问题描述】:
我有一个文本文件
0 Po Tom Mr 123AlphabetStreet Netherlands Wulu 123456 D01 Malaysia SmallAdventure 231112
0 Liu Jack Mr 123AlphabetStreet Italy Spain 123456 D02 Afghanistan TriersAdventure 030214
我正在尝试读取txt文件:Form.txt,将使用getline的每一行存储到变量foo中
这是工作程序
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
fstream afile;
afile.open("Form.txt",ios::in);
string foo;
while (getline(afile,foo,'\n') );
{
cout<<foo
<<endl;
}
}
没有任何东西打印到控制台输出,我期待
0 Po Tom Mr 123AlphabetStreet Netherlands Wulu 123456 D01 Malaysia SmallAdventure 231112
0 Liu Jack Mr 123AlphabetStreet Italy Spain 123456 D02 Afghanistan TriersAdventure 030214
相反,我得到了
我的代码有什么问题??
【问题讨论】:
-
感谢您的回复。您的可执行文件目录中有
Form.txt文件吗? -
@0x499602D2 是的,我有
-
在
while循环之前添加一个if (!afile) cout << "Something's wrong";并让我知道它是否打印。 -
@0x499602D2 它不打印
-
什么系统和编译器?
标签: c++ debugging text-files iostream