fork download
  1. #include <string>
  2. #include <iostream>
  3. #include <map>
  4. using namespace std;
  5.  
  6. struct Person {
  7. Person(std::string first, std::string last);
  8. std::string _first, _last;
  9. };
  10.  
  11.  
  12. ostream& operator<<(ostream& os, const Person& per){
  13. os << per._first << " " << per._last;
  14. return os;
  15. }
  16.  
  17.  
  18. struct SocialNetwork {
  19. void addUser(std::string first, std::string last);
  20. std::map<std::string, Person> _users;
  21. void printUsers();
  22. };
  23.  
  24.  
  25. void SocialNetwork::addUser(std::string first, std::string last){
  26. std::string name = (first + last);
  27. Person user (first, last);
  28. _users.insert(std::pair<std::string, Person>(name, user));
  29. }
  30.  
  31. Person::Person(std::string first, std::string last){
  32. _first = first;
  33. _last = last;
  34. }
  35.  
  36. void SocialNetwork::printUsers(){
  37. std::map<std::string, Person>::iterator it;
  38. it = _users.begin();
  39. while(it != _users.end()){
  40. cout << it->first << endl;
  41. cout << it->second << endl;
  42. it++;
  43. }
  44. }
  45.  
  46.  
  47. int main() {
  48. std::string cFirst ("Chris");
  49. std::string cLast ("Cringle");
  50. SocialNetwork sn;
  51. sn.addUser(cFirst,cLast);
  52. sn.printUsers();
  53. return 0;
  54. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
ChrisCringle
Chris Cringle