#include #include //for the i/o manipulator setw #include #include //for class string #include //for class map using namespace std; int main() { const map m { {"Kallax", "shelf unit"}, {"Ekenabben", "open shelf unit"}, {"Ivar", "2 section shelving unit"}, {"Skruvby", "sideboard"}, {"Besta", "storage combination with doors"}, {"Holmerud", "slide table"}, {"Skarpo", "armchair, outdoor"}, {"Revskar", "3-seat combination set"}, {"Nammaro", "3-seat modular sofa, outdoor"}, {"Billy", "bookcase"} }; 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 an IKEA word, 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 << " means " << it->second << "\n"; } } return EXIT_SUCCESS; //Arrive here when the user types control-d }