C++ peek() not seeing new line character
<p>I'm having some trouble reading input from a file that I really shouldn't be having on a homework assignment.  I've used very similar code (the only thing that's changed is where values get shoved) on previous a previous assignment.  I've been given a text file with the following input:</p>

<pre><code>10
3 6 4 9 0 7 8
8 5 3 7 3 4 -2
5 10 2 8 1 4 1
2 6 -3 1 3 7 1
1 10 -1 2 2 4 -2
10 9 -3 1 3 7 2 5 1
7 3 0 10 1 2 1 8 2
9 6 6 3 4 10 7
4 8 5 1 9 5 6
6 2 4 3 0 9 0
</code></pre>

<p>The first line is the number of vertexes present for the above graph.  On each line after, the first number is which vertex this is for, the next number is which vertex it is connected to, and the one after is the weight of that edge.  The line repeats vertex, weight until the end of the line (ie, the first line is for vertex 3, it has an edge to 6 with weight 4, an edge to 9 with weight 0, etc.).  I'm using a 1d vector to represent a matrix using row major notation.  The issue I'm having is that my row variable doesn't seem to be updating at all.  Currently, I get the following output from the last line in the while loop that actually plugs the data into the vector.</p>

<pre><code>3:  6: 4
3:  9: 0
3:  7: 8
3:  8: 5
3:  3: 7
3:  3: 4
3:  -2: 5
3:  10: 2
3:  8: 1
3:  4: 1
3:  2: 6
3:  -3: 1
3:  3: 7
3:  1: 1
3:  10: -1
3:  2: 2
3:  4: -2
3:  10: 9
3:  -3: 1
3:  3: 7
3:  2: 5
3:  1: 7
3:  3: 0
3:  10: 1
3:  2: 1
3:  8: 2
3:  9: 6
3:  6: 3
3:  4: 10
3:  7: 4
3:  8: 5
3:  1: 9
3:  5: 6
3:  6: 2
3:  4: 3
3:  0: 9
3:  0: 9
</code></pre>

<p>My row variable seems to be getting stuck as 3, like the input.peek() as the condition for the while loop is never seeing the new line character.  The really confusing part is that on a similar assignment, this chunk of code worked fine to iterate through the input file and stuff things where they were supposed to go.  I'm stumped, so if someone can point me in the right direction I would really appreciate it.  I apologize in advance if I've been too verbose.</p>

<p>My code is below.</p>

<pre><code>if(input.is_open()) // making sure the input is open
{
    input &gt;&gt; nodeCount; //Grabbing the number of nodes from the first value of the file

    for(int i = 1; i &lt; nodeCount*nodeCount; i++)
    {
        edgeList.push_back(graphNode());
        edgeList[i].value = infinity;
        edgeList[i].isInfinity = true;
        edgeList[i].pred = -1;
    }

    //Putting data from the file into the vector array
    while(!input.eof())
    {
        input &gt;&gt; row; //For each cycle through the list, we grab the first number on the line to get which x value (start vertex) we're working with
        while(input.peek() != '\n' &amp;&amp; !input.eof())
        {
            input &gt;&gt; col;
            input &gt;&gt; edgeList[((row-1)*nodeCount)+(col-1)].value;
            edgeList[((row-1)*nodeCount)+(col-1)].isInfinity = false;
            edgeList[((row-1)*nodeCount)+(col-1)].pred = row;
            cout &lt;&lt; row &lt;&lt; ": " &lt;&lt; " " &lt;&lt; col &lt;&lt; ": " &lt;&lt; edgeList[((row-1)*nodeCount)+(col-1)].value &lt;&lt; endl;
        }

    }
    input.close(); //Closing our input file since we don't need it anymore
}
</code></pre>
