fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main()
  5. {
  6. typedef std::vector<int> MyVec_t;
  7. MyVec_t MyVec;
  8.  
  9. for(MyVec_t::size_type i = 0; i < 10; ++i)
  10. {
  11. MyVec.push_back(i-1);
  12. MyVec.push_back(i+1);
  13. MyVec.push_back(i);
  14. }
  15.  
  16. for(MyVec_t::const_iterator it = MyVec.begin(); it != MyVec.end(); ++it)
  17. {
  18. std::cout << *it << ' ' << std::flush;
  19. }
  20.  
  21. std::cout << std::endl;
  22.  
  23. for(MyVec_t::iterator it = MyVec.begin(); it != MyVec.end(); /*nothing*/)
  24. {
  25. if(*it == 7)
  26. {
  27. it = MyVec.erase(it);
  28. }
  29. else ++it;
  30. }
  31.  
  32. for(MyVec_t::const_iterator it = MyVec.begin(); it != MyVec.end(); ++it)
  33. {
  34. std::cout << *it << ' ' << std::flush;
  35. }
  36. }
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
-1 1 0 0 2 1 1 3 2 2 4 3 3 5 4 4 6 5 5 7 6 6 8 7 7 9 8 8 10 9 
-1 1 0 0 2 1 1 3 2 2 4 3 3 5 4 4 6 5 5 6 6 8 9 8 8 10 9