Weird behaviour with std::getline and std::vector<std::string>
<p>I have the following code:</p>

<pre><code>std::vector&lt;std::string&gt; final_output;
std::string input;

int tries = 0;
std::cin &gt;&gt; tries;

int counter = 0;
while(counter &lt; tries) {

    std::getline(std::cin, input); 
    final_output.push_back(input);
    ++counter;

}
</code></pre>

<p>Given the input:</p>

<pre><code>3
Here Goes
Here Goes 2
</code></pre>

<p>The output is:</p>

<pre><code>&lt;blank line&gt;
Here Goes
Here Goes 2
</code></pre>

<p>Weirdly, it seems to enter a blank line as input for the first time it runs.</p>

<p>However, if I have the code as:</p>

<pre><code>int tries = 3;         // explicitly specifying the number of tries
int counter = 0;
while(counter &lt; tries) {}
</code></pre>

<p>It works as expected. Why is the <code>std::cin &gt;&gt; tries</code> causing the code to fail?</p>

<p>I have tested it with VC++ 2010 and g++ 4.4.3</p>
