Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign value of one iterator into another iterator C++

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++.

like image 930
neel Avatar asked Nov 02 '12 19:11

neel


1 Answers

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>.

like image 126
Kerrek SB Avatar answered Sep 28 '22 02:09

Kerrek SB