//----------------------------------------------------------------------------- // name: map.cpp // desc: basic STL map example // // Music 256a, Fall 2009, Stanford University // http://ccrma.stanford.edu/courses/256a-fall-2009/ // // compile: // g++ -o map map.cpp // run: // ./map //----------------------------------------------------------------------------- #include #include #include using namespace std; // entry point int main() { // a map of strings to ints map m; // insert value 24 mapped to key "foo" m["foo"] = 24; m["bar"] = 100; // print out cerr << m["foo"] << endl; // declare an iterator map::iterator iter; // iterate over map for( iter = m.begin(); iter != m.end(); iter++ ) { // print out key and value pairs cerr << (*iter).first << " " << (*iter).second << endl; } return 0; }