#include <iostream> #include <fstream> #include<iostream> using namespace std; int main() { char sourcename[80],destname[80],buffer[256]; int n; cout<<"请输入要复制的文件名(包含后缀名):"<<endl; cin>>sourcename; cout<<"请输入复制后的文件名(包含后缀名):"<<endl; cin>>destname; ifstream in(sourcename,ios_base::in|ios_base::binary); ofstream out(destname,ios_base::out|ios_base::binary); if(!in||!out){cerr<<"Open File Failure,Please Try Again!";exit(1);} while(!in.eof()) { in.read(buffer,256); //从文件中读取256个字节的数据到缓存区 n=in.gcount(); //由于最后一行不知读取了多少字节的数据,所以用函数计算一下。 out.write(buffer,n); //写入那个字节的数据 } in.close(); out.close(); return 1; }
时间: 2024-10-29 19:13:26