fork(1) download
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. vector<int> arr { 1,2,3,4,5,6,7,8,9 };
  8.  
  9. bool check(int n)
  10. {
  11. return n%2;
  12. }
  13.  
  14. int main(int argc, const char * argv[])
  15. {
  16. for(auto x: arr) cout << x << " "; cout << endl;
  17. arr.erase(remove_if(arr.begin(),arr.end(),[](auto x){ return !check(x); }),arr.end());
  18. for(auto x: arr) cout << x << " "; cout << endl;
  19. }
  20.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1 2 3 4 5 6 7 8 9 
1 3 5 7 9