c++ 2D vector for loop : <p>I have a text file with data and I have put that into a 2D vector. I can print all of the data with this loop. </p>

<pre><code>int M = 1024; int N = 768   // row / column
int R = 49; int C = 36      // row / column

for (double bx = 0; bx &lt; M; bx += R)
    for (double by = 0; by &lt; N; by += C)
    {
        for (int x = 0; ((x &lt; R) &amp;&amp; ((bx + x) &lt; M)); ++x)
        {
            for (int y = 0; ((y &lt; C) &amp;&amp; ((by + y) &lt; N)); ++y)
            {
                if ((bx + x) &gt;= M) 
                {
                    std::cout &lt;&lt; (bx + x) &lt;&lt; (by + y) &lt;&lt; " ";

                }
                cout &lt;&lt; MainIMG_2DVector[bx + x][by + y] &lt;&lt; " ";
            }
        }
        cout &lt;&lt; "\n\n\n" &lt;&lt; endl;
    }
</code></pre>

<p>If I want to get the first block of the data, I use this loop:</p>

<pre><code>for (int i = 0; i &lt; 49; i++)
    {
        for (int j = 0; j &lt; 36; j++)
        {
            cout &lt;&lt; MainIMG_2DVector[i][j] &lt;&lt; " ";
        }
    }
</code></pre>

<p>When I compare the First block with the Data from the text file, it is correct.</p>

<p>However if I get the Second Block of data and compare it with the text file, it is incorrect.</p>

<pre><code>for (int i = 49; i &lt; 98; i++)
    {
        for (int j = 36; j &lt; 72; j++)
        {
            cout &lt;&lt; MainIMG_2DVector[i][j] &lt;&lt; " ";
        }
    }
</code></pre>

<p>I know the second loop is wrong but I don't know how to fix this.
Can someone please help me.</p>
