打印

文件复制问题

[复制链接]
1020|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
dfsa|  楼主 | 2012-9-10 23:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include<iostream>
#include<fstream>
#include <string>
using namespace std;
int FileCopy(string SouFile,string DirFile)
{
ifstream in;
ofstream out;
in.open(SouFile.c_str(),ios::binary);
if (in.fail())
{
cout<<"Error:Fail to open the souFile."<<endl;
in.close();
out.close();
return 0;
}
out.open(DirFile.c_str(),ios::binary);
if (out.fail())
{
cout<<"Error:Fail to open the dirFile."<<endl;
in.close();
out.close();
return 0;

}
else
{
out<<in.rdbuf();
out.close();
in.close();
return 1;
}
}
void main()
{
ifstream config;
string index;
config.open("config.txt",ios::binary);
while (getline(config,index))
{
string sou="c:/";
string dir="e:/";
sou+=index;
dir+=index;
if (FileCopy(sou,dir))
{
cout<<"成功"<<endl;
}
else
{
cout<<"失败"<<endl;
}
}
config.close();
}
其中config.txt有文件名,要求把c盘的对应文件复制到e盘,但是源文件无法打开,提示Error:Fail to open the souFile.
但我c盘的确有对应文件呀。。

相关帖子

沙发
sinadz| | 2012-9-10 23:30 | 只看该作者
config.open("c:/config.txt",ios::binary);

使用特权

评论回复
板凳
火箭球迷| | 2012-9-10 23:41 | 只看该作者
string sou="c:\\";
string dir="e:\\";

使用特权

评论回复
地板
hsbjb| | 2012-9-10 23:52 | 只看该作者
在运行输入检查c:\asd.txt看能否打开文件
检查是否有文件打开了c:\asd.txt。工具:unlock

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

282

主题

2404

帖子

2

粉丝