fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7. vector<int> test;
  8. test.push_back(1);
  9. test.push_back(2);
  10. test.push_back(3);
  11.  
  12. for (vector<int>::iterator it = test.begin(); it != test.end(); )
  13. {
  14. cout << "Num [" << (*it) << "]" << endl;
  15.  
  16. if ((*it) == 2)
  17. it = test.erase(it);
  18. else
  19. it++;
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
Num [1]
Num [2]
Num [3]