In this article we will see how to erase elements from a std::list using iterators.

std::list provides 2 member function to delete elements using iterators i.e.

It deletes the element representing by passed iterator “position” and returns the iterator of element next to last deleted element.

It accepts a range of elements as an argument and deletes all the elements in range (firs, last] and returns the iterator of element next to last deleted element.

Output

 

To compile above code on Linux use following command,

g++ –std=c++11 example.cpp

 

 

In the next articles we will see how to erase elements using a criteria and also in a loop.

Thanks

Click Here to Subscribe for more Articles / Tutorials like this.