Monday, May 24, 2010

How do I delete a vector in c++?

I want to delete the whole vector and everything inside it. I tried "delete ListViewText;" But I got this error:


error: type `class std::vector%26lt;std::string, std::allocator%26lt;std::string%26gt; %26gt;' argument given to `delete', expected pointer

How do I delete a vector in c++?
you can delete a vector only if you allocated it with "new"
Reply:either use delete operator if u have created it using new


or to clear the vector use clear function provide by vector
Reply:It sounds like you want to remove all the items inside the vector. In that case, use the clear method:





vector.clear();





There is also a "remove" method if you want to remove only specific ranges of the vector.


No comments:

Post a Comment