Take the 2-minute tour ×

How many types of iterators are there in C++ STL? As of now, I know of these:

  • Output Iterator
  • Input Iterator
  • Forward Iterator
  • Random Access Iterator

Are there more? What are the differences between them? What are the limitations and characteristics of each? Which type is used when?

share|improve this question
add comment

4 Answers

up vote 6 down vote accepted

The C++ standard also has a Bidirectional Iterator concept, which is a Forward Iterator that can also go backward (with operator--). Together, these five form the entire iterator hierarchy in paragraph 24.2 of the C++ standard.

The old STL also had the concept of a Trivial Iterator. See its Iterator overview for details regarding the various iterators.

Boost designers Abrahams, Siek and Witt have presented a much more fine-grained set of iterator concepts.

share|improve this answer
add comment

If you can find and read "The C++ Standard Library: A Tutorial and Reference" there is a whole chapter of STL iterators.

Here is a little something from the book:

Iterator Category       Ability                                 Providers

Input iterator          Reads forward                           istream
Output iterator         Writes forward                          tream, inserter
Forward iterator        Reads and writes forward
Bidirectional iterator  Reads and writes forward and backward   list, set, multiset, map, multimap
Random access iterator  Reads and writes with random access     vector, deque string, array 
share|improve this answer
add comment

I suspect you know the answer pretty well, but anyway, these charts are very helpful in sorting this out

share|improve this answer
i suspect it too –  zkunov Mar 6 '11 at 17:21
add comment

This page from apache shows very good examples of the different types of iterators along with their differences.

share|improve this answer
add comment

Your Answer


