The Remove and erase functions in C + + STL used to confuse me and delete, what's the difference between the two?
The action of remove in a vector is to place an element equal to value at the tail of the vector, but does not reduce the size of the vector
The role of erase in vectors is to remove elements from a position position or section (begin, end), reducing their size
The Remove member function in the list container, the prototype is void remove (const value_type& val), and the function is to delete the node in the list with the same value as Val, freeing the node's resources.
The erase member function in the list container, the prototype is iterator erase (iterator position), and the function is to delete the node of the position location.
Considering the list::erase is related to the position, so erase also exists api:iterator erase (iterator first, iterator last);
For set, there is only erase API, there is no remove API. The role of erase is to delete the elements that meet the requirements.
(1) Void erase (iterator position);
(2) Size_type Erase (const value_type& val);
(3) Void erase (iterator first, iterator last);
In summary, erase is generally to release resources, really delete elements,
Remove is used primarily in vectors to move non-conforming elements to the end of a container without deleting elements that do not meet the requirements
Stl:remove and Erase differences