+ 1
how to compare current and previous element in list
Hi Refer code below: map<string, vector<string>> data; has vector as value. If I need list as value, how to iterate over list? We can iterate with begin and end, but how to compare last element with current element for list? https://www.sololearn.com/compiler-playground/cn5CwUsYlr6Y
3 Answers
+ 2
Have you tried using std::prev () ?
https://en.cppreference.com/w/cpp/iterator/prev
https://code.sololearn.com/c4566RUf3hUn/?ref=app
+ 2
Ketan Lalcheta "std::advance ()" doesn't return anything, it simple advances the iterator passed to it.
+ 1
I was trying advance with -1.. is it correct ? I was getting incomplete type error with below :
auto pv = std::advance(it,-1);