Say I have an iterator it
which is pointing to some element of map
.
Also I have another iterator it1
, and I want to do something like this
it1 = it + 1;
How can we achieve this in C++ as above statement gives error in C++.
In C++11, you say auto it1 = std::next(it, 1);
.
Prior to that, you have to say something like:
std::map<K, T>::iterator it1 = it;
std::advance(it1, 1);
Don't forget to #include <iterator>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With