【C++训练】将两个文件合并成一个文件

#include <iostream>
using namespace std;
#include "fstream"


void read_write(char *ifname, char *ofname="G://sum.txt")
{
	if (ifname!=ofname)
	{
		char c[256];
		ifstream ifile(ifname);
		ofstream ofile(ofname, ios::app);
		while (!ifile.eof()) /// eof = end of file
		{
			ifile.getline(c, 255);
			cout << c << endl;
			ofile << c << endl;
		}
		ifile.close();
		ofile.close();
	}
	else
	{
		cout << "error " << endl;
	}
}



void main()
{
	read_write("G://123.txt","G://123.txt");
	read_write("G://456.txt","G://999.txt");
    cout<<"hello"<<endl;
	system("pause");
	return;
}
    原文作者:今天写文章了吗?
    原文地址: https://blog.csdn.net/weixin_42810844/article/details/87628070
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞