I've got a fairly long program I'm working on and am having difficulty deleting an element from a vector. I've tried to do it with a very simple vector, and am having the same problem. As far as I can see, I've done it the same way everybody has explained in other people's questions. Here is the simple code.
vector<int> vect;
vect.push_back(3);
vect.push_back(2);
cout << vect[1]; // prints '2'
vect.erase(vect.begin()+1);
cout << vect[1] << endl; // prints '2'
What am I doing wrong?
It seems the above code works, because I checked the size at the end, and it printed '1'. The real code doesn't though:
size = A[i]->B().size();
cout << "size is " << A[i]->B().size() << endl; // prints 21
A[i]->B().erase(A[i]->B().begin()+size);
cout << "size now " << A[i]->B().size() << endl; // prints 21
I can't see what I've done differently? A is a vector, which stores other vectors. I want to delete the last element in the B vector.