string::erase() gives different result in linux/windows
<p>I have a piece of code which reads in a line from a file, then removes the whitespace and tells you the length of the string. In windows it works as I expect it to, however in linux it returns a different result.</p>

<p>Code:</p>

<pre><code>    // Find how many characters are in the first line
    std::string line;
    std::ifstream map ("level1.map");

    getline(map,line);

    // Remove whitespace from the string to get the useful length of line
    for ( unsigned int i = 0, j ; i &lt; line.length( ) ; ++ i )
    {
        if ( line [i] == ' ' )
        {
            for ( j = i + 1; j &lt; line.length ( ) ; ++j )
            {
                if ( line [j] != ' ' )
                    break ;
            }

            cout &lt;&lt; j;
            line = line.erase ( i, (j - i) ) ;
        }
    }

   // Output
   cout &lt;&lt; line.size() &lt;&lt; endl;
</code></pre>

<p>It's essentially just trying to determine how many tile columns there are in the map file, where the map is formatted thusly on each line:</p>

<p>2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2</p>

<p>And so whitespace needs to be removed.</p>

<p>In windows given an initial line length of 160 the end length is 80, however when compiled in linux the initial length is 160, but the end length is 81. The only place the value becomes different appears to be after line = line.erase ( i, (j - i) ) ;</p>

<p>Any ideas why this is happening?</p>
