Containers

The Standard Library containers allow you to group together zero or more items of the same type and access them serially through iterators. Every such object has a begin method that returns an iterator object to the first item and an end function that returns an iterator object for the item after the last item in the container. The iterator objects support pointer-like arithmetic, so that end() - begin() will give the number of items in the container. All container types will implement the empty method to indicate if there are no items in the container, and (except for forward_list) the size method is the number of items in the container. You are tempted to iterate through a container as if it is an array:

 vector<int> primes{1, ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.