cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
difference between erase and clear
difference between erase and clear
Apr 4, 2014 at 8:57am UTC
naveen2525
(24)
vector<int> *vec; allocate memory and
suppose vec conatins 10 values then
erase(vec->begin(),vec->end());
vec.clear();
both should be used or any one one is fine to erase all ??
Apr 4, 2014 at 9:02am UTC
kbw
(9488)
clear() removes all entries from a collection.
erase() can remove a single entry or a range of entries. In your example, the range is the entire content, so the effect is the same as clear().
Topic archived. No new replies allowed.