C++ erase function
erase is a function in vector used toremoves the element at a specified positionfunction; it is the most flexible way to delete in the container.
erase is a member function of the container class, used toRemoves one or more elements at a specified position in the container. It accepts iterator arguments.
erase Provides the ability to delete elements at any position, although in vector it is less efficient than pop_back(which requires moving subsequent elements), but it is more powerful.
Word meaning: erase means "erase," i.e., to remove the element at the specified position.
Basic syntax and parameters
erase is a member function of the container class; it needs to specify the iterator of the deletion position.
Syntax format
// Delete element at pos position
iterator erase(iterator pos);
// Delete all elements in the range [first, last)
iterator erase(iterator first, iterator last);
Parameter Description
- Parameters:
pos - Type: iterator (
iterator) - Description: the position of the element to delete.
The C++ container class