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. int main()
  9. { int x=2;
  10. row rows[]={{"1","BB","r1"},{"2","AA","r2"}};//=new row[x];
  11. std::sort(rows,rows+x,[](const row& r1, const row& r2){return r1.name<r2.name;});
  12. for(int i=0;i<x;++i)
  13. {
  14. //getline(fin, rows[i].ID, '\t'); // ID
  15. //getline(fin, rows[i].name, '\t'); // name
  16. //getline(fin, rows[i].rest );
  17. cout<<rows[i].ID<<'\t'<< rows[i].name<<'\t'<< rows[i].rest<<endl;
  18. }
  19. }
  20.  
Success #stdin #stdout 0s 3036KB
stdin
Standard input is empty
stdout
2	AA	r2
1	BB	r1