Skip to main content

6.1) Standard Container Types


C++ provides various standard container types to simplify the storage and manipulation of collections of values, the main ones being:

  • Vectors, for holding sequences of values in cases where ordering is important
  • Lists, similar to vectors but with different performance characteristics
  • Sets, which guarantee the uniqueness of values and support efficient checking of whether a particular value is present
  • Maps, which allow us to store and look up values using an associated key

We focus on vectors in this section; lists, sets and maps are covered in the next section. Using these standard containers is generally easier than using lower-level storage such as arrays.

Note that containers are templates - incomplete pieces of C++ code - so to use them we must supply an additional piece of information: the type of value to be stored.