 <p>Here is one way to copy <code>n</code> <code>double</code>s into a vector:</p> <pre><code>#include &lt;vector&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;iterator&gt; int main() { unsigned n; std::vector&lt;double&gt; xvec; std::cin &gt;&gt; n; xvec.reserve(n); std:generate_n(std::back_inserter(xvec), n, []() { double d; std::cin &gt;&gt; d; return d; }); std::copy(xvec.begin(), xvec.end(), std::ostream_iterator&lt;double&gt;(std::cout, " ")); std::cout &lt;&lt; "\n"; return 0; } </code></pre> <hr> <p><strong>Note</strong>: This alternative using <code>std::copy_n</code> won't work:</p> <pre><code>std::copy_n(std::istream_iterator&lt;double&gt;(std::cin), n, std::back_inserter(xvec)); </code></pre> <p>This actually reads <code>n+1</code> elements but only copies <code>n</code> of them (at least on g++ 4.6.3).</p> <hr> <p><strong>Note 2</strong>: Limiting the answer to C++98, here is one possible solution:</p> <pre><code>double GetD() { double d; std::cin &gt;&gt; d; return d; } ... std:generate_n(std::back_inserter(xvec), n, GetD); </code></pre>