对,所以我已经设法让我的程序连接我的两个文本文件,我现在需要对创建的文本文件进行排序,以便它们按数字顺序显示。例如说 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;
}