fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <list>
  4.  
  5.  
  6. int main()
  7. {
  8. int nums[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  9. std::vector<int> u(std::begin(nums), std::end(nums));
  10. std::list<int> v(std::begin(nums), std::end(nums));
  11.  
  12. for (auto it = u.begin(); it != u.end(); )
  13. {
  14. if (*it % 2 == 0)
  15. it = u.erase(it);
  16. else
  17. ++it;
  18. }
  19.  
  20. for (auto it = v.begin(); it != v.end(); )
  21. {
  22. if (*it % 2)
  23. it = v.erase(it);
  24. else
  25. ++it;
  26. }
  27.  
  28. for (auto &i : u)
  29. std::cout << i << " ";
  30. std::cout << std::endl;
  31. for (auto &i : v)
  32. std::cout << i << " ";
  33. std::cout << std::endl;
  34.  
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
1 3 5 7 9 
2 4 6 8 10