Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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
it
map
it1
it1 = it + 1;
How can we achieve this in C++ as above statement gives error in C++.
operator+
std::next
In C++11, you say auto it1 = std::next(it, 1);.
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>.
#include <iterator>
Add a comment
std::next(it)
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
operator+.std::nextwould do that.