fork(2) download
  1. #include <string>
  2. #include <list>
  3. #include <iostream>
  4. struct A {
  5. std::string name;
  6. A(const std::string& name) : name(name) {}
  7. bool operator< (const A& right) const { return name < right.name; }
  8. };
  9.  
  10. int main()
  11. {
  12. std::list<A> list = {A("c"), A("a"), A("b")};
  13. list.sort();
  14.  
  15. // ideone.com's compiler is rather old
  16. // for(auto a : list)
  17. // std::cout << a.name << '\n';
  18. for(auto i = list.begin(); i!=list.end(); ++i)
  19. std::cout << i->name << '\n';
  20. }
  21.  
Success #stdin #stdout 0s 2964KB
stdin
Standard input is empty
stdout
a
b
c