fork download
  1. #include <iostream>
  2. #include <map>
  3.  
  4. class Employee
  5. {
  6. int id = 0;
  7. public:
  8.  
  9. explicit Employee(int id) : id{id} {}
  10.  
  11. friend std::ostream& operator << (std::ostream& os, const Employee& e)
  12. {
  13. return os << "Employee(id=" << e.id << ")";
  14. }
  15. };
  16.  
  17. int main() {
  18. std::map<std::string, Employee> employee {
  19. {"Karl", Employee{42}},
  20. {"George", Employee{59}},
  21. };
  22.  
  23. for (const auto& p : employee ) {
  24. std::cout << p.first << " " << p.second << std::endl;
  25. // George Employee(id=59)
  26. // Karl Employee(id=42)
  27.  
  28. }
  29. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
George Employee(id=59)
Karl Employee(id=42)