Iterator to last element in std::list

Posted by Dave18 on Stack Overflow See other posts from Stack Overflow or by Dave18
Published on 2010-04-20T19:52:23Z Indexed on 2010/04/20 20:03 UTC
Read the original article Hit count: 131

Filed under:
|
#include <list>
using std::list;

int main()
{
    list <int> n;
    n.push_back(1);
    n.push_back(2);
    n.push_back(3);

    list <int>::iterator iter = n.begin();
    std::advance(iter, n.size() - 1); //iter is set to last element
}

is there any other way to have an iter to the last element in list?

© Stack Overflow or respective owner

Related posts about c++

Related posts about stl