Nawaz Nawaz - 8 months ago 90
C++ Question

Types of iterator : Output vs. Input vs. Forward vs. Random Access Iterator

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?


If you can, find and read "The C++ Standard Library: A Tutorial and Reference". This book contains a whole chapter about STL iterators.

Here is a little something from the book:

Iterator Category  Ability                          Providers
-----------------  -------------------------------  ----------------------------
Input iterator     Reads forward                    istream
Output iterator    Writes forward                   ostream, inserter
Forward iterator   Reads/writes forward             forward_list,
Bidirectional it.  Reads/writes forward/backward    list, [multi]set, [multi]map
Random access it.  Reads/writes with random access  vector, deque string, array