C++ : iterating the vector
<p>I'm very new to C++ and I'm trying to learn the vector in C++..</p>

<p>I wrote the small program as below. I like to foreach(var sal in salaries) like C# but it doesn't allow me to do that so I googled it and found that I have to use iterator.. Im able to compile and run this program but I dont get the expected output.. I'm getting "0 0 0 0 0 0 1 2 3 4 5 6 7 8 9" instead of "0 1 2 3 4 5 6 7 8 9".. </p>

<p>Could anyone please explain me why? Thanks. </p>

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

using namespace std;

void show(int i)
{
  cout &lt;&lt; i &lt;&lt; " ";
}

int main(){

    vector&lt;int&gt; salaries(5);

    for(int i=0; i &lt; 10; i++){
        salaries.push_back(i);
    }

    for_each(salaries.begin(), salaries.end(), show);   
}
</code></pre>
