title: Iterating over an std::vector when vector size changes. (C++)
body: <p>I wrote a very simple code that iterates over a vector. The problem is that this vector changes its size on each iterator.</p>
  
  <p>The vector is a private variable of a class. And the code goes like this:</p>
  
  <pre><code>std::vector&lt;boost::filesystem::path&gt; headerVector;
  </code></pre>
  
  <p>The loop is a for loop inside a member function of the same class.</p>
  
  <p>It seems that the for loop reads the vector size once and then iterates until that number is reached, but the vector increases it's size on some iterations (not infinite).</p>
  
  <p>How can I make it iterate until the value of IT and the CURRENT size of the vector are equal?</p>
  
  <p>The code goes like this:</p>
  
  <pre><code>void HeaderObtainer::mapIterator( boost::filesystem::path aPath )
  {
      bool exist;
      std::vector&lt;boost::filesystem::path&gt;::iterator it; //iterator for boost path.
  
      for (it = headerVector.begin(); it!= headerVector.end(); it++) // For each?
          {
              aPath = *it;
              exist = HeaderSources::fileExists( aPath ); //Returns bool.
              fileSearch ( exist, aPath );
          }
  }
  </code></pre>
  
  <p>Thank you!</p>