I need to traverse stl list in c++ till end() - 1, what is the efficient way to do this?
#include <iostream>
#include <list>
using namespace std;
int main()
{
list<int> l{1,2,3,4,5};
for(auto itr = l.begin(); itr != l.end() - 1; ++itr)
{
cout << *itr << '\n';
}
}
Aucun commentaire:
Enregistrer un commentaire