Standard Map 1
#include <iostream> #include <string> #include <map> #include <stdlib.h> using namespace std; main() { map<string, string> dict; dict["mouse"] = "squeek"; dict["cat"] = "meow"; dict["dog"] = "woof"; dict["bird"] = "tweet"; dict["snake"] = "sssss"; map<string, string>::iterator i = dict.begin(); for(; i != dict.end(); ++i) cout << i->first << ": " << i->second << endl; }

The map takes a key type (any type that supports inquality comparison) and a data type (pretty much anything) and operates like an array subscripted by the key type. (This sort of structure is often known as a dictionary.)

It supports the common iterator construct, except each item has two parts, the key and data, known by the creative names first and second.