#include<iostream> |
#include<fstream> |
#include<io.h> |
#include<windows.h> |
using namespace std ; |
/**复制文件 |
filename :要复制的文件名 |
newfile :要复制到的文件名 |
*/ |
int cpy( char *filename, char *newfile) |
{ |
ifstream in ; |
ofstream out ; |
/** |
open函数的原型是 |
open(const char*filename,ios_base::openmode mode=ios_base::in) ; |
in_stream.open("file.txt");这样写参数实际上是指向这个常量字符串的指针 |
*/ |
//打开文件 |
in.open(filename); |
//打开文件失败 |
if (in.fail()){ |
cout<< "打开文件失败" <<endl ; |
in.close(); |
out.close(); |
return 0 ; |
} |
out.open(newfile); |
if (out.fail()){ |
cout<< "创建文件失败" <<endl ; |
in.close(); |
out.close(); |
return 0 ; |
} else { //复制文件 |
out<<in.rdbuf(); |
out.close(); |
in.close(); |
return 1 ; |
} |
} |