Iterating, inserting and removing?
<h3>Dream output:</h3>

<pre><code> /* DREAM OUTPUT:
 INT: 1
 TESTINT: 1
 TESTINT: 2
 TESTINT: 23
 TESTINT: 24
 TESTINT: 25
 TESTINT: 3
 TESTINT: 4
 TESTINT: 5
 TESTINT: 6
 INT: 23
 INT: 24
 INT: 25
 INT: 3
 INT: 4
 INT: 5
 INT: 6
</code></pre>

<h3>Problem</h3>

<pre><code> ERROR 1: Not erasing the '2' causes a bizzare effect.
 ERROR 2: Erasing the '2' causes memory corruption.
</code></pre>

<h3>Code</h3>

<pre><code> #include &lt;cstdlib&gt;
 #include &lt;iostream&gt;
 #include &lt;vector&gt;

 int main(int argc, char* argv[])
 {
    std::vector&lt;int&gt; someInts;

    someInts.push_back(1);
    someInts.push_back(2);
    someInts.push_back(3);
    someInts.push_back(4);
    someInts.push_back(5);
    someInts.push_back(6);

    for(std::vector&lt;int&gt;::iterator currentInt = someInts.begin();
        currentInt != someInts.end(); ++currentInt)
     if(*currentInt == 2)
     {
        std::vector&lt;int&gt; someNewInts;

        someNewInts.push_back(23);
        someNewInts.push_back(24);
        someNewInts.push_back(25);

        someInts.insert(currentInt + 1, someNewInts.begin(), someNewInts.end());
        //someInts.erase(currentInt);

        for(std::vector&lt;int&gt;::iterator testInt = someInts.begin();
            testInt != someInts.end(); ++testInt)
         std::cout &lt;&lt; "TESTINT: " &lt;&lt; *testInt &lt;&lt; '\n';
     }
     else
        std::cout &lt;&lt; "INT: " &lt;&lt; *currentInt &lt;&lt; '\n';

    return 0;
 }
</code></pre>

<p>The code is pretty self-explanatory, but I'd like to know what's going on here. This is a replica using ints of what's happening in a much larger project. It baffles me.</p>
