copy to vector giving segfault
<p>I am trying to copy the vector data from <code>sample</code> to <code>Y</code> as below</p>

<pre><code>std::map&lt;std::string, std::vector&lt;double &gt; &gt;sample;
std::map&lt;std::string, std::vector&lt;double &gt; &gt;::iterator it1=sample.begin(), end1=sample.end();
std::vector&lt;double&gt; Y; 
</code></pre>

<p>and am using the following code:</p>

<pre><code> while (it1 != end1) {
  std::copy(it1-&gt;second.begin(), it1-&gt;second.end(), std::ostream_iterator&lt;double&gt;(std::cout, " "));
++it1;
}
</code></pre>

<p>It prints the output ok, however when I replace the above std::copy block with the below, I get a segfault.</p>

<pre><code> while (it1 != end1) {
std::copy(it1-&gt;second.begin(), it1-&gt;second.end(), Y.end());
++it1;
}
</code></pre>

<p>I just want to copy the contents of it1->second to Y. Why is it not working and how do I fix it?</p>
