------------------------------------------------------------------------------
MC logo
Standard Containers
[^] CSc 220 Home
------------------------------------------------------------------------------
[Introduction] [Boolean and Control] [Functions] [Arrays and Pointers] [Dynamic Arrays] [Array Errors] [Command Array] [Standard Containers] [Structs and Classes] [Automatic Pointer] [Multi-File Programs] [Copying Objects] [Templates] [Inheritance] [Plain C I/O] [Type Odds And Ends] [Plain C Strings] [File I/O]
[STL Vector 101] [STL Sorting Vectors] [stlist_cpp] [STL Map 1] [STL Map 2] [Word Counter]
Reading: Chapter 25

The C++ standard libraries include several very useful standard container classes. Containers are just data structures which hold other things, an they are very useful. The structures are vector, deque (both array-like structures of variable size), list (which is doubly-linked), set, multiset, map and multipmap. The last four allow fast search based on a key, and they are generally implemented using a tree structure.

The 2011 standard added unordered_set, unordered_multiset, unordered_map and unordered_multimap. These are similar in behavior to the existing structures, but based on hashing rather than a tree.

Associated with each container is an appropriate iterator class which allows a program to step through the contents of the container. It is designed to behave much like a pointer, which can be initialized to the first item and incremented in a loop to step through the whole array.

Whatever<i> c;
. . .
for(Whatever<i>::iterator i = c.begin(); i != c.end(); ++i) {
        // Use *i to access the current item.
}