#include"iostream"
#include"string"
#include"fstream"
using namespace std;
class file{
private:
static int length;
public:
file(){};
static void copy(string srcFileName,string targetFileName);
void getlength(){
cout << "文件长度为:" << length << endl ;
}
};
void file::copy(string srcFileName,string targetFileName){
char ch;
cout << srcFileName << endl ;
ifstream in(srcFileName.data(),ios::in|ios::binary);
ofstream out(targetFileName.data(),ios::out|ios::binary);
while(in.get(ch))
{
out.put(ch);
length++;
}
in.close();
out.close();
}
int file::length=0;
void main()
{
file f;
string srcFileName,targetFileName;
cout << "请输入源文件名(格式:磁盘名:\\文件名.文件格式)" << endl ;
cin >> srcFileName;
cout << srcFileName << endl ;
cout << "请输入目标文件名(格式:磁盘名:\\文件名.文件格式)" << endl ;
cin >> targetFileName;
f.copy(srcFileName,targetFileName);
f.getlength();
}
编写一个类,该类具有统计文件长度,实现文件复制的函数。 其中复制功能函数如: void copy(string srcFileName,string targetFileName);
最新推荐文章于 2024-08-01 18:41:57 发布