/* CSE 333 Su12 lecture 12 demo: mapexample.cc */ /* Gribble/Perkins */ // Store several pairs of Printer objects in a map, then print // the table, and print some individual values using table lookup. #include #include #include #include "Printer.h" using namespace std; void PrintOut(const pair &p) { cout << "printout [" << p.first << "," << p.second << "]" << endl; } int main(int argc, char **argv) { Printer a, b, c, d, e, f; map table; map::iterator it; cout << "About to do insert (a,b)" << endl; table.insert(pair(a, b)); cout << "About to do table[c] = d" << endl; table[c] = d; cout << "About to do table[e] = f" << endl; table[e] = f; cout << "table[e]:" << table[e] << endl; it = table.find(c); cout << "PrintOut(*it), where it = table.find(c)" << endl; PrintOut(*it); cout << "iterating:" << endl; for_each(table.begin(), table.end(), &PrintOut); cout << "About to do table[f]..." << endl; cout << "table[f]:" << table[f] << endl; return 0; }