fork download
  1. #include <map>
  2. #include <ostream>
  3. #include <string>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. class Osoba {
  8.  
  9. public :
  10. string imie, nazwisko;
  11. int ID;
  12.  
  13. Osoba(string i, string n, int id) {imie = i; nazwisko = n, ID = id;}
  14. bool operator==(const Osoba &q) {return ID ==q.ID && imie == q.imie && nazwisko == q.nazwisko;}
  15. friend ostream & operator<< (ostream &wyjscie, const Osoba &s);
  16. };
  17.  
  18.  
  19. ostream & operator<< (ostream &wyjscie, const Osoba &s)
  20. {
  21. return (wyjscie << s.imie << " " << s.nazwisko << " " << s.ID << "\n");
  22. }
  23.  
  24. int main()
  25. {
  26.  
  27. Osoba o1("Jan", "Kowalski", 123);
  28. Osoba o2("Adam", "Nowak", 1234);
  29. Osoba o3("Anna", "Kowalska", 12345);
  30.  
  31. map<const int, Osoba> osoby;
  32. map<const int, Osoba>::iterator it;
  33.  
  34. osoby.insert(make_pair(1, o1));
  35. osoby.insert(make_pair(2, o2));
  36. osoby.insert(make_pair(3, o3));
  37.  
  38. it = osoby.begin();
  39.  
  40. for ( it=osoby.begin() ; it != osoby.end(); it++ )
  41. cout << (*it).first << " => " << (*it).second << endl;
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 2864KB
stdin
Standard input is empty
stdout
1 => Jan Kowalski 123

2 => Adam Nowak 1234

3 => Anna Kowalska 12345