Delete all items from a c++ std::vector

后端 未结 9 1280
陌清茗
陌清茗 2020-12-04 09:42

I\'m trying to delete everything from a std::vector by using the following code

vector.erase( vector.begin(), vector.end() );

9条回答
  •  星月不相逢
    2020-12-04 10:24

    vector.clear() should work for you. In case you want to shrink the capacity of the vector along with clear then

    std::vector(v).swap(v);
    

提交回复
热议问题