The end iterator is not the last element, but an iterator past the last element.
If you simply need to erase elements from the front or back,
http://www.cplusplus.com/reference/stl/list/pop_back/
http://www.cplusplus.com/reference/stl/list/pop_front/
If you have an index and wish to erase an element in the middle,
http://www.cplusplus.com/reference/std/iterator/advance/
If you are iterating through your list to erase elements,
1 2 3 4 5 6 7 8 9 10 11 12
|
for (auto it = my_list.begin(); it != my_list.end();)
{
if (...) // erase condition
{
it = my_list.erase(it); // erase will invalidate the iterator,
// but returns a new iterator to the next element.
}
else
{
++it;
}
}
|
Though in that case, a much better solution is to use the remove_if algorithm,
http://en.wikipedia.org/wiki/Erase-remove_idiom
Finally, are you sure list is the appropriate choice for your container?
http://www.linuxsoftware.co.nz/containerchoice.png