fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <iterator>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. bool f(int i) {return i > 2;}
  9.  
  10. int main() {
  11. vector<int> v;
  12. v.push_back(1);
  13. v.push_back(2);
  14. v.push_back(3);
  15. v.push_back(4);
  16. v.push_back(5);
  17. vector<int>::iterator it;
  18. it = std::remove_if( v.begin(), v.end(), f); // shift v.erase( it, v.end()); }
  19. copy( v.begin(), it, ostream_iterator<int>(cout));
  20. // but it will still gives us vector of size 5
  21. copy( v.begin(), v.end(), ostream_iterator<int>(cout));
  22. // so let's erase
  23. v.erase( it, v.end());
  24. copy( v.begin(), v.end(), ostream_iterator<int>(cout));
  25. return 0;
  26. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
121234512