title: How to fix error "vector iterators in range are from different containers" in c++?
body: <p>I don't know where is the problem. The program crashes in this function. Can you help me?</p>
  
  <p>I use these 2 functions for benchmarking (comparing containers speed with different techniques of using it). I use vector "studentai" with all students name and lastname in it. At vector "silpni" are students, which final score is >5. And, of course, "geri" with score &lt;5. This function work well:</p>
  
  <pre><code>void atrinkimas_1(vector &lt;duomenys&gt;&amp; studentai, vector &lt;duomenys&gt;&amp; silpni, vector &lt;duomenys&gt;&amp; geri)
  {
      sort(studentai.begin(), studentai.end(), tikrinimas_gal);
      std::vector&lt;duomenys&gt;::iterator it = std::find_if(studentai.begin(), 
      studentai.end(), tikrinimas_5);
      std::copy(it, studentai.end(), std::back_inserter(geri));
      studentai.resize(studentai.size() - geri.size());
      std: copy(studentai.begin(), it, std::back_inserter(silpni));
      studentai.clear();
  }
  </code></pre>
  
  <p>And this doesn't:</p>
  
  <pre><code>void atrinkimas_2(vector &lt;duomenys&gt;&amp; studentai, vector&lt;duomenys&gt; &amp;silpni)
  {
      sort(studentai.begin(), studentai.end(), tikrinimas_gal);
      std::vector&lt;duomenys&gt;::iterator it = std::find_if(studentai.begin(), studentai.end(), tikrinimas_5);
      std::copy(it, studentai.end(), std::back_inserter(silpni));
      studentai.resize(studentai.size() - silpni.size());
  }
  </code></pre>
  
  <p>What is the problem?</p>