difference between erase and clear


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 ??
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.