那个c++李德vector类 有一个push_back()的函数可以给后面追加对象
那有没有什么函数能从里面删除对象啊? 书上好像没说
我也没找到
pop_back
remove,呵呵
erase ps:大鸟你当是java的vector呀:)
erase就可以了
erase ~
那就erase吧。
One important thing to know, the vector.erase() is different from vector.pop_back().
the vector.pop_back() will not delete the object in memory, but the vector.erase() will. so careful, if u just want to pop the object, do not want to delete it, u'd better use the pop_back(), and if u know what u r doing, then the erase() is ok.
and more, the vector.erase() the input value is not int, not like vector.erase(int a), here, the input is a relative value to begin or end, so the right call method is like this:
vecotr.erase(vector.begin()+ (int position));
for vector.pop_back(), it is ok.
more, the vector.erase(vector.begin()); means delete the first element in the vector.
thank u
|