我不能读书出文件内容,是不是哪里没搞好?用outfile和infile进行操作.

hdp4820 2004-03-23 11:33:30
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

main()
{
ofstream outfile( "out_file" );
ifstream infile( "in_file" );
if(!infile)
{
cerr<<"error,the in_file can't read"<<endl;
return -1;
}
if(!outfile)
{
cerr<<"error,the out_file can't write"<<endl;
return -2;
}
string str;
while(infile>>str)
outfile<<str<<' '<<endl;
return 0;
}

文件"out_file和in_file都建立在当前目录下
...全文
54 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
laiweiguo 2004-04-22
  • 打赏
  • 举报
回复
我帮你调了一下~~~

这样应该可以了~~~

你看看行不行?

#include <iostream.h>
#include <fstream.h>
#include <string.h>


int main()
{
ofstream outfile( "out_file.txt" );
ifstream infile( "in_file.txt" );
if(!infile)
{
cout<<"error,the in_file can't read"<<endl;
return -1;
}
if(!outfile)
{
cout<<"error,the out_file can't write"<<endl;
return -2;
}
String str;
while(infile>>str)
outfile<<str<<' '<<endl;
return 0;
}
redfaceeggs 2004-04-02
  • 打赏
  • 举报
回复
我手边没有编译器 那位老大给看看 很想知道原因
redfaceeggs 2004-04-01
  • 打赏
  • 举报
回复
楼上说的不对 人家已经进行判断了 我觉得你的while的条件有问题吧 >> 操作符返回istream对象好像什么时候也不能为空吧 能终止循环吗?

Jinhao 2004-03-23
  • 打赏
  • 举报
回复
关键是,你创建 in_file没有,注意没有后缀名哟!或者统改为
main()
{
ofstream outfile( "out_file.txt" ); //注意是txt文件哟
ifstream infile( "in_file.txt" ); //注意是txt文件哟
...

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧