You likely want x = A.erase(x)
. vector::erase
returns an iterator to the element following the one that's erased.
The reason A.erase(x); --x;
doesn't work is because erase(x)
invalidates the iterator. The only thing you can do with x
afterwards is assign a new value to it.