Possible Duplicate:
Difference between erase and remove
suppose i have a container.... what does the following mean.
c.erase(remove(c.begin(),c.end(),99),c.end());
aren't erase and remove the same? What is the specific function of erase and remove in the above example?
It removes all elements equal to 99
from container c
.
std::remove
doesn't actually remove any elements. It moves all the elements of interest to the second part of the container, and returns an iterator indicating the first of these. Then the erase
member function takes an iterator range to actually remove the elements from the container.
See erase-remove idiom.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With