是的,所以我设法让我的程序连接我的两个文本文件,我现在需要对创建的文本文件进行排序,使它们按数字顺序出现.例如,说Test1.txt包含数字1,2,3,4,5,Test2包含数字4,5,6,8,myoutput.txt应该包含1,2,3,4,4,5,5, 6,8.我并不熟悉排序算法.我猜我必须读取输出文件,对它们进行排序并再次写入输出文件.
这是我目前的代码:
#include <iostream>
#include <fstream>
#include <ostream>
using namespace std;
int main()
{
//collecting integers from first text file//
ifstream file1("test1.txt", ios::in | ios::binary);
if(!file1)
{
cout << "Cannot open input test file 1.\n";
return 1;
}
// collecting integers from second text file//
ifstream file2("test2.txt", ios::in | ios::binary);
if(!file2)
{
cout << "Cannot open input test file 2.\n";
return 1;
}
//outputting the concactonated file to myoutput.txt//
ofstream cout("myoutput.txt", ios::out | ios::binary);
if(!cout)
{
cout << "can't open output file ";
return 1;
}
cout << file1.rdbuf();
cout << " " << flush;
cout << file2.rdbuf();
ifstream sortfile("myoutput.txt, )
return 0;
}
Run Code Online (Sandbox Code Playgroud)