C++ insertion sort from a txt file
<p>I have to read from a .txt file and out it with a different .txt file. I have to use insertion sort in order to sort them based on two numbers. I could only get this far, I don't know how to do insertion sort in this program where I have two numbers to sort to. </p>

<p>Here is my code:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;

using namespace std;

int main(void)
{
    int serialno[100], suratno[100], ayatno[100];
    string order;

    string str;
    char ch;
    int i = 0;
    int j, temp;

    ifstream fin;
    fin.open("text.txt");

    if(!fin)
    {
        cout &lt;&lt; "Cannot open file \'text.txt\'! Quitting.\n";
        exit(0);
    }

    while(fin)
    {

        fin.get(ch); //gets .

        getline(fin, order, '('); //allegedly it removes the delimiter char from stream too

        fin &gt;&gt; suratno;
        fin.get(ch); //gets :
        fin &gt;&gt; ayatno;
        fin.get(ch); //gets )
        fin.get(ch); //gets \n

        cout &lt;&lt; serialno &lt;&lt; "." &lt;&lt; order &lt;&lt; "("&lt;&lt;suratno&lt;&lt;":&lt;&lt;ayatno&lt;&lt;")\n";
    }

    fin.close();

    //sort algorithm            
    for (int i = 0; i &lt; length; i++){
        j = i;

        while (j &gt; 0 &amp;&amp; suratno [j] &lt; suratno [j-1]){
              temp = suratno [j];
              suratno [j] = suratno [j-1];
              suratno [j-1] = temp;
              j--;
              cout &lt;&lt; serialno &lt;&lt; endl;
              }
        }
    }

    ofstream fout;
    fout.open("newtext.txt");

    if(!fout)
    {
        cout &lt;&lt; "Cannot open output file\'orderedquranorders.txt\'!Quitting.\n";
        exit(0);
    }

    i = 0;
    //write sorted list to output file

    fout.close();

    cout &lt;&lt; i &lt;&lt; " orders successfully sorted and written.\n";
}
</code></pre>

<p>this is the text file (numbers in bracket should be used, firstly with number before colon, and secondly with number after colon):</p>

<pre><code>1. Do not be rude in speech (3:159) 
2. Restrain Anger (3:134)
3. Be good to others (4:36)
4. Do not be arrogant (7:13)
5. Forgive others for their mistakes (7:199)
6. Speak to people mildly (20:44)
7. Lower your voice (31:19)
8. Do not ridicule others (49:11)
9. Be dutiful to parents(17:23)
</code></pre>

<p>current output:</p>

<ol>
<li>Do not be rude in speech (3:159) </li>
<li>Restrain Anger (3:134)</li>
<li>Be good to others (4:36)</li>
<li>Be dutiful to parents(17:23)</li>
</ol>

<p>expected output:</p>

<ol>
<li>Restrain Anger (3:134)</li>
<li>Do not be rude in speech (3:159)</li>
<li>Be good to others (4:36)</li>
<li>Be dutiful to parents(17:23)</li>
</ol>

<p>sorted in terms of both the numbers and the serial no stays the same</p>