c++ declararion variables in for loop
<p>Question is about variables inside the loop. How does it works?
Similar questions:<br>
<a href="http://stackoverflow.com/questions/982963/is-there-any-overhead-to-declaring-a-variable-within-a-loop-c">one</a><br>
<a href="http://stackoverflow.com/questions/407255/difference-between-declaring-variables-before-or-in-loop">two</a></p>

<p>code:</p>

<pre><code>for ( i = 0 ; i &lt; 3 ; i++ ) {
   vector&lt;int&gt; vint;
   vint.push_back(i);
   cout &lt;&lt; "vecor size is: " &lt;&lt; vint.size() &lt;&lt; endl;
   for ( j = 0 ; j &lt; vint.size() ; j++ ) {
       cout &lt;&lt; "vint[" &lt;&lt; j &lt;&lt; "] = " &lt;&lt; vint[j] &lt;&lt; endl;
   }
}
</code></pre>

<p>above code gives next output:    </p>

<pre><code>vecor size is: 1   
vint[0] = 0
vecor size is: 1
vint[0] = 1
vecor size is: 1
vint[0] = 2
</code></pre>

<p>It looks like that in the end of each iteration method sdt::vector::erase is called or somehow vint becomes again empty. How does it work, and how did you figure out it? thank you!</p>

<p>UPDATE:<br>
If I want different vector in each iteration what is better:<br>
declare vint in the loop<br>
or declare it before the loop and use clear() in the end of the loop?</p>
