Original Post
I'm new to vectors so this might seem like a stupid question but I just can't figure it out. This code is just a test for something else actually. As I'm looping through a vector I will want it to erase a certain item if some certain condition is true. It seems to work in this code at least unless the item to be erased is the last item in the vector. It will let me erase any of the other items except the last one (like if I tested *iter == 20 instead of *iter == 40 it would work) Heres my code: Any help would be great!
vector<int> intVec;
vector<int>::iterator iter;
intVec.push_back(10);
intVec.push_back(20);
intVec.push_back(30);
intVec.push_back(40);
for(iter = intVec.begin(); iter != intVec.end(); iter++)
{
if(*iter == 40)
intVec.erase(iter);
}