文件流复制数据到文件 , 将文件1.txt的内容复制到2.txt 中

#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream f1;
char ch;
f1.open("1.txt");
if (!f1)
{
cout<<"不能打开1.txt文件\n";return 0;
}
ofstream f2;
f2.open("2.txt");
if (!f2)
{
cout<<"不能打开2.txt文件\n";return 0;
}
while (f1.get(ch))
{
f2.put(ch);
}
cout<<"IS Over!\n";
return 0;
}

你可能感兴趣的:(文件流复制数据到文件 , 将文件1.txt的内容复制到2.txt 中)