title: Sort integers from text file in C++
body: <p>Right, so I've managed to get my program to concatenate my two text files, I now need to sort the created text file so they appear in numerical order. For example say Test1.txt contains the numbers 1,2,3,4,5 and Test2 contains the numbers 4,5,6,8, myoutput.txt should have 1,2,3,4,4,5,5,6,8. I'm not massively familiar with sorting algorithms. I'm guessing I'll have to read the output file, sort them and the write to the output file again. </p>
  
  <p>Here is my current code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;ostream&gt;
  
  using namespace std;
  
  int main()
  {
      //collecting integers from first text file//
     ifstream file1("test1.txt", ios::in | ios::binary);
     if(!file1)
     {
        cout &lt;&lt; "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 &lt;&lt; "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 &lt;&lt; "can't open output file ";
        return 1;
     }
  
     cout &lt;&lt; file1.rdbuf();
     cout &lt;&lt; " " &lt;&lt; flush;
     cout &lt;&lt; file2.rdbuf();
  
     ifstream sortfile("myoutput.txt, )
  
     return 0;
  }
  </code></pre>