fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <array>
  5.  
  6.  
  7. class O {
  8. std::string n;
  9. int a;
  10.  
  11. public:
  12.  
  13. O(const char* c, int a = 1) : a(a), n(c) {}
  14.  
  15. const std::string& get_n() const { return n; }
  16.  
  17. };
  18.  
  19. bool bfunction(const O& a, const O& b) {
  20. return a.get_n() < b.get_n();
  21. }
  22.  
  23. int main() {
  24.  
  25. std::array<O, 4> m = { "unta", "jalan", "sama", "aki" };
  26.  
  27. std::sort(m.begin(), m.end(), &bfunction);
  28.  
  29. for(auto& x : m) {
  30. std::cout << x.get_n() << ',';
  31. }
  32. }
Success #stdin #stdout 0s 4572KB
stdin
Standard input is empty
stdout
aki,jalan,sama,unta,