#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盘的确有对应文件呀。。 |