fork(1) download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. //erases the indicie of the given integer
  5. void erase(std::vector<int*> &x, int n){
  6. int i = 0;
  7. while (*(x[i]) != n){
  8. i++;
  9. }
  10. std::cout << &x << "\n";
  11. delete x[i];
  12.  
  13. std::cout << &x << "\n";
  14.  
  15. x.erase(x.begin() + i);
  16.  
  17. std::cout << &x << "\n";
  18. }
  19.  
  20. int main () {
  21.  
  22. std::vector<int*> x;
  23. std::vector<int*> * p;
  24.  
  25. // say i initiated x with a couple of integers
  26. p = &x;
  27.  
  28. std::cout << p << " " << &x << "\n";
  29.  
  30. x.push_back(new int(1));
  31. x.push_back(new int(2));
  32. x.push_back(new int(3));
  33.  
  34. std::cout << p << " " << &x << "\n";
  35.  
  36. erase(*p, 2);
  37.  
  38. std::cout << p << " " << &x << "\n";
  39.  
  40. }
  41.  
Success #stdin #stdout 0s 3016KB
stdin
Standard input is empty
stdout
0xbf969728 0xbf969728
0xbf969728 0xbf969728
0xbf969728
0xbf969728
0xbf969728
0xbf969728 0xbf969728