In the following sample code remove_if
is supposed to delete all even numbers but it is not working as I expect. I am obviously doing something wrong since the output continues to show some even numbers, towards the end.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool
myCond(int i) { return i % 2 == 0; }
int
main ()
{
vector<int> myVector = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22};
remove_if(myVector.begin(), myVector.end(), myCond);
for(int i : myVector) cout << i << " ";
cout << endl;
return 0;
}
output 11 13 15 17 19 16 17 18 19 20 22