首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++程序有关问题,下面的程序是输出wr1.txt文件中的数据,但编译时发现if(f1>>i)这句有有关问题,请教要怎样改?

2012-03-27 
C++程序问题,下面的程序是输出wr1.txt文件中的数据,但编译时发现if(f1i)这句有问题,请问要怎样改???错误

C++程序问题,下面的程序是输出wr1.txt文件中的数据,但编译时发现if(f1>>i)这句有问题,请问要怎样改???
错误提示:error C2676: binary '>>' : 'class ofstream' does not define this operator or a conversion to a type acceptable to the predefined operator



#include <iostream.h>

#include <stdlib.h>
#include <fstream.h>

void main()
{
ofstream f1("wr1.txt", ios::in|ios::nocreate);
if(!f1)
{
cerr<<"File 'wr1.txt' not found";
exit(1);
}

int i;
while(!f1.eof())
{
if(f1>>i)
cout<<i<<" ";
}
cout<<endl;
f1.close();
}

[解决办法]
ofstream 改成ifstream
[解决办法]
f1<<i
[解决办法]

探讨

ofstream 改成ifstream

热点排行