C i, j, k; // C is a "less than comparable" type, which means "i < j" is defined (and sensible. By which I mean it is anti-reflexive: i < i is false and transitive: i < j, j < k implies i < k. This is called a strict weak ordering. Note that it can be for some i and j of type C that neither i < j nor j < i is true. Then i and j may be considered equivalent -- in fact this can be taken as a definition of equality for elements of C. T t, u; // any type T map m; // declare a vector; m.size();// is 0 m.[i] = t; // put t in the map with index i. m.[j] = t; // same value at index j now. m.size();// is 2 u = m[i]; // u is t m[k]; // if index k has not been used before, m[k] takes on the default value of type T. ...and it is now a stored value with index k in the map. m.size(); // is 3 now. map::iterator p; // pointer into map *p is a pair of index (type C) and value (type T). p->first is the index, p->second is the value. (assuming p is a valid initialized iterator.) m.begin(); //iterator pointing to m[i], where i is the least index where a value has been assigned so far. p++ pointer to the next index, value that has been assigned, by index order. m.end(); //iterator pointing to an invalid pair. Used when an iterator "falls off the end of the map". Similar role to a null pointer. // standard use of iterator: for (p = m.begin(); p != m.end(); ++p) { process *p, i.e. do things with p->first and p->second } m.clear() // equiv: w.resize(0) m.empty() // equiv: w.size() == 0 Key points. index type can be int, float (double), char, string, etc. value type can be anything. operator[] runs in time proportional to log(current size of the map). It is fast enough for most applications. Conclusion: maps are powerful! Example: Word count program #include #include using namespace std; int main() { map wc; string s; while (cin >> s) wc[s]++; map::iterator p; for(p = wc.begin(); p != wc.end(); ++p) cout << p->first << " occurrence count is " << p->second << endl; } } Remarks: