Unknown size vector input
<p>here is the question.
I have a vector of ints, and user should enter it's elements as long as he or she want. Then, this vector is passed to a function, which calculates it's size for whatever reason. Is there any way to do so? I found some code on shores of the Internet:</p>

<pre><code>std::vector&lt;int&gt; vec;

std::string buffer = "";

std::cout &lt;&lt; "Enter numbers. "
          &lt;&lt; "After you finish, enter newline" &lt;&lt; std::endl;

do {
    std::getline(std::cin, buffer);
    if (buffer.size() &gt; 0) {
        vec.push_back(atoi(buffer.c_str())); //stoi was not declared =(
    }
} while (buffer != "");

foo(vec);
....
void foo(std::vector&lt;int&gt; &amp;input)
{
    for (const int &amp;i : input)
        {
            std::cout &lt;&lt; i &lt;&lt; endl;
        }
}
</code></pre>

<p>But this code doesn't works in right way: I choose entering numbers and it just does nothing. Have no idea what's wrong with it.
(c++11 enabled)</p>