If my std::vector has 1890 elements, and I want to keep the first 1000 and erase 开发者_Python百科the rest,and then again next 890 elements and erase the first 1000,.. so a loop seems to be necessary.
Is there a more convenient way to do this?std::vector
has an erase
member function that allows you to erase a range of elements without using an explicit loop. For example:
std::vector<whatever> x(1890);
// erase first 1000 items
x.erase(x.begin(), x.begin()+1000);
精彩评论