文件的复制

//实现文件的复制
#include <iostream>
#include<fstream>
using namespace std;
int main()
{
   ifstream readFile;
   ofstream writeFile;
   char ch;//定义字符变量
   readFile.open("a.txt",ios::in);
   writeFile.open("b.txt",ios::out);
   while(readFile.get(ch))
    writeFile.put(ch); //将a中的字符一个一个地写入到b中,实现文件的复制
   readFile.close();
   writeFile.close();
   cout<<"Finish!"<<endl;
   return 0;
}

//实现文件的复制
#include <iostream>
#include<fstream>
#include<cstring>
using namespace std;
int main()
{
   ifstream readFile;
   ofstream writeFile;
   char ch[100];
   readFile.open("a.txt",ios::in);
   writeFile.open("a2.txt",ios::out);
   while(!readFile.eof())
   {
       readFile.getline(ch,100,'\n');
       writeFile.write(ch,strlen(ch));
       writeFile.write("\n",1);
   }
   readFile.close();
   writeFile.close();
   cout<<"Finish!"<<endl;
   return 0;
}

你可能感兴趣的:(文件的复制)