samedi 29 août 2015

increment begin() (of a list) in c++ stl doesn't work

I have this code

list<int> p {5,3,6,2,1};
vector<int> v {2,3,4};
cout<<*(v.begin() + 1);
cout<<*(p.begin() +1);

I get output of the 3rd line as 3 but the 4th line shows this error

no match for 'operator+' (operand types are 'std::list<int>::iterator {aka std::_List_iterator<int>}' and 'int')

What's wrong here .. why does the increment doesn't work with a list pointer..?

Aucun commentaire:

Enregistrer un commentaire