以下代码实现把d1.txt和d2.txt中的内容合并到d3.txt,d1的内容在前,d2在后:
#include <fstream>
using namespace std;
int main()
{
char* f1 = "d1.txt";
char* f2 = "d2.txt";
char* f3 = "d3.txt";
ifstream inFile1( f1 );
ifstream inFile2( f2 );
ofstream outFile( f3 );
outFile << inFile1.rdbuf();
outFile << inFile2.rdbuf();
inFile1.close();
inFile2.close();
outFile.close();
}
如果是以二进制方式合并,也是这么写吗? |