Chapter 12

Understanding Containers and Iterators


  • What iterators are
  • What the different container classes are and how to use them

Chapter 11 introduced the STL, described its basic philosophy, and provided an overview of the various containers and algorithms. You should be familiar with Chapter 11 before you tackle Chapter 12.

This chapter begins a tour of the STL by covering the STL containers, including the following:

  • Containers Overview: requirements on elements, general error handling, and iterators
  • Sequential Containers: vector, deque, list, array, and forward_list
  • Container Adapters: queue, priority_queue, and stack
  • Associative Containers: the pair utility, map, multimap, set, and multiset
  • Unordered Associative Containers/Hash Tables: unordered_map, unordered_multimap, unordered_set, and unordered_multiset
  • Other Containers: standard C-style arrays, strings, streams, and bitset

A detailed list of available classes and methods can be found in the Standard Library Reference resource on the website.

The next chapters will go deeper in on topics like algorithms, strings, regular expressions, I/O and how you can customize and extend the STL.


Containers in the STL are generic data structures useful for storing collections of data. You should rarely need to use a standard C-style array, write a linked list, or design a stack when you use the STL. The containers are implemented as templates, which allow you to instantiate them for any ...

Get Professional C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.