注册 登录
编程论坛 VC++/MFC

请高手帮忙看看这道题应该怎么改正错误。

happysteven 发布于 2010-12-01 21:18, 549 次点击
编写程序,将abc.txt的内容复制到xyz.txt文件中。谢谢高手帮助!
#include<fstream>
#include<iostream>
using namespace std;

int main()
{
ofstream out;
out.open("D:\\abc.txt");
if(!out)
{
    cout<<"Can't open output file"<<endl;
    return 0;
}
out<<9<<endl;
out.close();
return 0;
ifstream in("D:\\abc.txt");
if(!in)
{ cout<<"Can't open input file"<<endl;  return 0; }
int i;
in.read((char*)&i, sizeof(int));
cout<<i<<endl;
in.close();
return 0;
ofstream out1;
out1.open("D:\\xyz.txt");
if(!out1)
{
    cout<<"Can't open output file"<<endl;
    return 0;
}
out1<<i<<endl;
out1.close();
return 0;
}


[ 本帖最后由 happysteven 于 2010-12-1 22:38 编辑 ]
5 回复
#2
zhijinwen2010-12-01 22:54
请问有什么算法错误吗?
#3
happysteven2010-12-01 23:01
回复 2楼 zhijinwen
不知道怎么做这道题啊,请帮忙,谢谢!
#4
ytchfp2010-12-02 09:19
int main()
{
ofstream out;
out.open("D:\\abc.txt");
if(!out)
{
    cout<<"Can't open output file"<<endl;
    return 0;
}
out<<9<<endl;
out.close();
return 0;

???????????????????????
这里出现的return 0;就直接返回主函数了,那后面的代码还有什么意义?

[ 本帖最后由 ytchfp 于 2010-12-2 09:21 编辑 ]
#5
happysteven2010-12-02 09:45
回复 4楼 ytchfp
请您帮我改一下可以吗?谢谢!
#6
laoyang1032010-12-03 19:09
只有本站会员才能查看附件,请 登录

试试我写过的这个   我的只不过是把一个文件的信息添加到另一个的末尾  道理是一样的
1