fork download
  1. #include <utility>
  2. #include <algorithm>
  3. #include <string>
  4. #include <iostream>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9. int main () {
  10.  
  11.  
  12. std::map<string,int> map1;
  13.  
  14. map1["ymax"]=10;
  15. map1["ymin"]=16;
  16. map1["xval"]=10;
  17.  
  18. std::map<string,int> map2;
  19.  
  20. map2["ymax"]=16;
  21. map2["ymin"]=20;
  22. map2["xval"]=28;
  23.  
  24. std::map<string,int> map3;
  25.  
  26. map3["ymax"]=16;
  27. map3["ymin"]=20;
  28. map3["xval"]=10;
  29.  
  30. vector<map<string,int>> v{map1, map2, map3};
  31.  
  32. std::sort(v.begin(), v.end(), [](std::map<string,int> &lhs, std::map<string,int> &rhs){
  33. return tie(lhs["ymax"], lhs["ymin"], lhs["xval"]) < tie(rhs["ymax"], rhs["ymin"], rhs["xval"]);
  34. });
  35. for(map<string,int> my_map : v){
  36. cout << "ymax" << ", " << my_map["ymax"] << endl;
  37. cout << "ymin" << ", " << my_map["ymin"] << endl;
  38. cout << "xval" << ", " << my_map["xval"] << endl;
  39. cout << "=======================\n";
  40. }
  41. }
  42.  
  43.  
Success #stdin #stdout 0s 3500KB
stdin
Standard input is empty
stdout
ymax, 10
ymin, 16
xval, 10
=======================
ymax, 16
ymin, 20
xval, 10
=======================
ymax, 16
ymin, 20
xval, 28
=======================