文件复制问题

[复制链接]
 楼主| 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

粉丝
快速回复 在线客服 返回列表 返回顶部