Why doesn't vector::clear remove elements from a vector?

前端 未结 10 2495
我寻月下人不归
我寻月下人不归 2020-11-29 07:29

When I use clear() on a std::vector, it is supposed to destroy all the elements in the vector, but instead it doesn\'t.

Sample

10条回答
  •  囚心锁ツ
    2020-11-29 07:59

    Yes this is normal. clear() doesn't guarantee a reallocation. Try using resize() after clear().

提交回复
热议问题