#include #include #include #include #include using namespace std; int main() { const map m { {"NewYork", 8478072}, {"Yonkers", 211569}, {"Hastings", 9289}, {"DobbsFerry", 11541}, {"Irvington", 6653}, {"Tarrytown", 11860} }; cout << "The map contains " << m.size() << " pairs:\n\n"; for (const auto& pair: m) { cout << setw(9) << left << pair.first << " = " << pair.second << "\n"; } for (;;) { cout << "\n"; cout << "Please type a town to see population, or control-d to quit: "; string ik; cin >> ik; if (!cin) { break; //The user typed control-d } const auto it {m.find(ik)}; //it is an "iterator". if (it == end(m)) { cerr << "Could not find " << ik << "\n"; } else { cout << ik << " the population is " << it->second << "\n"; } } return EXIT_SUCCESS; //Arrive here when the user types control-d }