注册 登录
编程论坛 C++教室

为什么用fstream没有输出

醉生梦死 发布于 2007-08-25 13:50, 727 次点击

初学c++,学习文件流这块遇到输出问题,代码如下
#include<fstream>
#include<iostream>
using namespace std;

int main()
{
ifstream in("inputfile.txt");
ofstream out("outputfile.txt");
for(string str;getline(in,str);)
out<<str<<endl;

return 0;
}
其中inputfile.txt,outputfile.txt都和此代码的cpp文件放在同一源代码文件夹中了
intputfile中手动输入的是:
a b
d e
a j
f k
d l
h j
f l
为什么outputfile中没有任何输出?
我用的是eclipse c++


2 回复
#2
_woebird2007-08-25 21:27

将for(string str;getline(in,str);)改成for(string str;in;getline(in,str))就可以了!
我也是新手!
大家多关照下

#3
醉生梦死2007-08-26 02:16
回复:(_woebird)将for(string str;getline(in,str)...
果然好用,谢谢了,以后还得多指教
1