fork download
  1. //http://stackoverflow.com/a/15968507/1458030
  2. #include <string>
  3. #include <algorithm>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7. struct row{string ID, name, rest;};
  8.  
  9. bool operator < (const row& r1, const row& r2)
  10. { return r1.name<r2.name;}
  11.  
  12. ostream &operator<<(ostream&o, const row&r)
  13. { return o<<r.ID<<'\t'<< r.name<<'\t'<< r.rest<<endl; }
  14.  
  15. int main()
  16. { int x=2;
  17. row rows[]={{"1","BB","r1"},{"2","AA","r2"}};//=new row[x];
  18. std::sort(rows,rows+x);
  19. for(int i=0;i<x;++i)
  20. cout<<rows[i];
  21. }
  22.  
Success #stdin #stdout 0s 3036KB
stdin
Standard input is empty
stdout
2	AA	r2
1	BB	r1