hello experts, i create a link list of char and input a lot of words in it.
and now i wanna use iterator to modify it,
if the current element is 'c' and next element is 'p', then do sth.
what can i do for getting the next element
i try iterator + 1, but compile error.
if you write this *itr-- it's a matter of priority which is executed first. I'd say it is (*it)--. So you decrease the content. this *(it--) would lead to an endless loop or crash.
To solve that problem you can write it like so:
1 2 3 4 5 6 7 8 9 10 11
list<char>::iterator prev_itr = words.end();
for(itr = words.begin(); itr != words.end(); itr++){
//if the previous *itr is equal to 'c' then cout the *itr
if(prev_itr != words.end())
{
if(*prev_itr == 'c')
cout << *itr << endl;
}
++prev_itr;
}