I'm trying to remove all instances of certain values from a vector, however when there are only one or two instances of the same value, one instance of the value remains:
//Removing any values in arr that match the values in copies
vector<int> arr = {100,100,50,40,40,20,10};
vector<int> copies = {100,40};
for(int i = 0; i < copies.size(); i++)
{
vector<int>::iterator j = find(arr.begin(), arr.end(), copies[i]);
arr.erase(j);
}
With this code, arr returns as {100,50,40,20,10} but if there are three or more instances of these values, .erase will remove them all
If anybody could explain why having one or two of the same value will save one from being erased I would greatly appreciate it.