title: How the iterator is invalid in a vector for erase function if i handling it?
body: <p>Here is my code</p>
  
  <pre><code>  std::vector&lt;int&gt; myvector;
    int i=1;
    for ( i=1; i&lt;=50; i++) myvector.push_back(i);
    for ( i=0; i&lt;50; i++) 
    {
        if(myvector[i]%2==0)
          {
              myvector.erase(myvector.begin()+i);
              i--;
          }
    }
  </code></pre>
  
  <p>Here i am trying to remove all the even numbers and after erasing an even number i am adjustingthe counter variable. But i am not getting the desired result.Why?</p>