Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4.  
  5. int main()
  6. {
  7.     std::map<std::string, std::string>
  8.         phonebook;
  9.  
  10.     phonebook.emplace(
  11.         std::pair<std::string, std::string>
  12.         {"Baabel", "08-5522134"}
  13.     );
  14.  
  15.     phonebook["Santa Maria"] = "08-344887";
  16.     phonebook["Turtles"] = "08-5555595";
  17.  
  18.     for (const auto& entry : phonebook)
  19.     {
  20.         std::cout << entry.first << " - "
  21.                   << entry.second << "\n";
  22.     }
  23.  
  24.     std::string input;
  25.  
  26.     std::cout << "Enter name\n";
  27.     while(std::getline(std::cin, input))
  28.     {
  29.         if (input.empty())
  30.             break;
  31.  
  32.         if (phonebook.count(input) != 0)
  33.             std::cout << phonebook[input] << "\n";
  34.         else
  35.             std::cout << "not in phonebook\n";
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement