// Program to demonstrate use of the map template class. #include #include #include using std::cout; using std::endl; using std::map; using std::string; int main( ) { map planets; planets["Mercury"] = "Hot planet"; planets["Venus"] = "Atmosphere of sulfuric acid"; planets["Earth"] = "Home"; planets["Mars"] = "The Red Planet"; planets["Jupiter"] = "Largest planet in our solar system"; planets["Saturn"] = "Has rings"; planets["Uranus"] = "Tilts on its side"; planets["Neptune"] = "1500 mile-per-hour winds"; planets["Pluto"] = "Dwarf planet"; cout << "Entry for Mercury - " << planets["Mercury"] << endl << endl; if (planets.find("Mercury") != planets.end( )) cout << "Mercury is in the map." << endl; if (planets.find("Ceres") == planets.end( )) cout << "Ceres is not in the map." << endl << endl; cout << "Iterating through all planets: " << endl; map::const_iterator iter; for (iter = planets.begin( ); iter != planets.end( ); iter++) { cout << iter->first << " - " << iter->second << endl; } return 0; }