If my std::vector has 100 elements and I want to save only the first 10 and erase the rest, is there a convenient way to do this?
std::vector
vec.resize(10); // drops the rest (capacity remains the same)
Yes, there is an erase function that takes arguments for the first and last.
v.erase(v.begin() + 10, v.end());
vec.erase(vec.begin() + 10, vec.begin() + 100);
theVector.erase(theVector.begin() + 10, theVector.begin() + 100);