[cpp]
//實現文件的復制
#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>
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;
}
[cpp]
//實現文件的復制
#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;
}
//實現文件的復制
#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;
}