std::map<T>::iterator refers to a bidirectional iterator of the iterator class. They have only ++ and -- operators. +N and [] are available only for random access iterators (which can be found, for example, std::vector<T> ).
The reason for this is that adding N to a random access iterator is a constant time (for example, add N*sizeof(T) to T* ), whereas for the same iterator, a bidirectional iterator needs to be applied ++ N times.
What you can do though (if you have C ++ 11):
std::map<int, int>::const_iterator pIterTwo = std::next(pSomeMap.begin(),1);
which does the right thing for all types of iterators.
source share