Standard Template Library

Container classes

Containers are classes that are used to hold other objects. For example, a list is a container that holds data and links the data objects together. There are a number of container classes in the STL.

Vector example

Vectors grow when you add elements. They are not pre-allocated like arrays. So you can't insert randomly. Before you can insert v[10] you must insert v[0-9]. Vectors are different from lists in that you can randomly access elements. The vector size is the actual number of elements in the vector. The capacity of a vector may be larger than the size as the vector will allocate a few extra spaces when it resizes to add an element.