fork download
  1. #include <map>
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. class PhonebookEntry
  7. {
  8. public:
  9. explicit PhonebookEntry(string name) : name(name) {}
  10.  
  11. void add(string type, string number) {numbers[type] = number;}
  12. map<string,string> & getNumbers() {return numbers;}
  13.  
  14. private:
  15. string name;
  16. map<string,string> numbers;
  17. };
  18.  
  19. int main() {
  20. PhonebookEntry pb1("olaNormann");
  21. pb1.add("Home","11234567");
  22. pb1.add("Work","11065432");
  23. cout << pb1.getNumbers()["Home"] << endl;
  24. cout << pb1.getNumbers()["Work"] << endl;
  25.  
  26. map<string,string>::iterator it;
  27. for(it = pb1.getNumbers().begin(); it != pb1.getNumbers().end(); ++it){
  28. cout << (*it).first << ": " << (*it).second << endl;
  29. }
  30. }
  31.  
Success #stdin #stdout 0.02s 2864KB
stdin
Standard input is empty
stdout
11234567
11065432
Home: 11234567
Work: 11065432