标题:我的文件输入与输出怎么打不开呢?
只看楼主
泾水荣梦
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2005-6-3
 问题点数:0 回复次数:6 
我的文件输入与输出怎么打不开呢?

#include<iostream> #include<fstream> #include<string> #include<cstdlib> //#include"in_file" //#include"out_file"

using namespace std;

int main() { ofstream outfile; ifstream infile; infile.open("income.com"); outfile.open("tax.out"); if(!outfile) { cerr<<"error:unable to open output file!\n"; return -2; } if(!infile) { cerr<<"error:unable to open input file!\n"; return -1; }

string word; while(infile>>word) outfile<<word<<' '; infile.close(); outfile.close(); return 0; } 运行时总是说 unable to open input file 各位可否告诉我是怎么回事呢?

搜索更多相关主题的帖子: include infile open 文件 
2005-06-03 23:48
rl
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2005-4-2
得分:0 
在同一目录里必须有你定义的这个文件
2005-06-04 14:51
shan183
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2005-5-30
得分:0 
是呀,你所要打开的文件必须在和你的程序文件同一目录下!
2005-06-04 19:32
泾水荣梦
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2005-6-3
得分:0 
我知道啊
都在一个文件夹中 啊

真小人和伪君子 从来只有勾结 用合作只会玷污这个词眼
2005-06-08 16:42
shan183
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2005-5-30
得分:0 

是因为你那个文件扩展名系统不识别,要写实际中存在的扩展名,帮你搞定了,自己运行一下! #include<iostream> #include<fstream> #include<string>

using namespace std;

int main() { ofstream outfile; ifstream infile;

infile.open("income.txt"); if(!infile) { cerr<<"error:unable to open input file!\n"; return -1; }

outfile.open("tax.txt"); if(!outfile) { cerr<<"error:unable to open output file!\n"; return -2; } string word; while(infile>>word) { outfile<<word<<' '; cout<<word<<' '; } cout<<endl; infile.close(); outfile.close();

return 0; }

2005-06-09 10:21
shan183
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2005-5-30
得分:0 
兄弟,我对你程序中的这段有点兴趣,哈哈! while(infile>>word) { outfile<<word<<' '; }
2005-06-09 10:25
泾水荣梦
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2005-6-3
得分:0 
多谢指教

真小人和伪君子 从来只有勾结 用合作只会玷污这个词眼
2005-06-15 10:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-20043-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.248557 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved