fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <iterator>
  4. #include <algorithm>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. struct Osoba
  9. {
  10. size_t wiek;
  11. string imie;
  12.  
  13. bool operator<( const Osoba &rhs ) const
  14. {
  15. return wiek < rhs.wiek;
  16. }
  17. };
  18.  
  19. std::ostream& operator<<(std::ostream& s, const Osoba& osoba)
  20. {
  21. return s << osoba.wiek << " " << osoba.imie;
  22. }
  23.  
  24. int main() {
  25.  
  26. vector<Osoba> osoby{
  27. { 19, "mateusz" },
  28. { 13, "jan" },
  29. { 20, "matek" },
  30. { 200, "cos" },
  31. { 133, "asia" }
  32. };
  33.  
  34. sort( osoby.begin(), osoby.end() );
  35.  
  36. copy( osoby.begin(),
  37. osoby.end(),
  38. ostream_iterator<Osoba>( cout, "\n" ) );
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
13 jan
19 mateusz
20 matek
133 asia
200 cos