| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 460 人关注过本帖
标题:这样写有错吗
只看楼主 加入收藏
猪也聪明
Rank: 1
等 级:新手上路
帖 子:156
专家分:0
注 册:2005-5-16
收藏
 问题点数:0 回复次数:2 
这样写有错吗

我想用递归的方法输出aaa.txt文件中的整数,以下代码有问题吗
#include<iostream>
#include<fstream>
using namespace std;
test(ifstream a);
int main()
{
ifstream in("d:\\aaa.txt");
test(in);
return 0;
}
test(ifstream a)
{
int n;
if(a.eof())
{
cout<<"file is over:\n";

return 0;
}
a>>n;
cout<<n<<" ";

test(a);

}
请高手赐教

搜索更多相关主题的帖子: include return file 
2006-03-17 14:22
jianwufeng
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2006-3-4
收藏
得分:0 
我学的还没有那么远,看不懂~~

我该为自己负责了
2006-03-17 14:25
名人
Rank: 1
等 级:新手上路
威 望:1
帖 子:205
专家分:0
注 册:2006-3-3
收藏
得分:0 

有错误,这样改吧:

#include<iostream>
#include<fstream>
using namespace std;

void test(ifstream a)
{
int n;
if(a.eof()) {
cout<<"file is over:\n";
exit(-1);
}
a>>n;
cout<<n<<endl;

test(a);
}

int main()
{
ifstream in("d:\\aaa.txt");
test(in);
return 0;
}


未必钱多乐便多,财多累己招烦恼。 清贫乐道真自在,无牵无挂乐逍遥。
2006-03-17 14:35
快速回复:这样写有错吗
数据加载中...
 
   



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

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