fork(5) download
  1. #include <map>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iostream>
  5.  
  6. int main()
  7. {
  8. std::map<int, int> m = {{1, 10}, {2, 5}, {4, 6}, {6, 1}};
  9. using mypair = std::pair<int, int>;
  10.  
  11. std::vector<mypair> v(begin(m), end(m));
  12.  
  13. std::sort(std::begin(v), std::end(v), [](const mypair& a, const mypair& b) { return a.second < b.second; });
  14.  
  15. for(auto const &p : v)
  16. std::cout << "m[" << p.first << "] = " << p.second << std::endl;
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 4300KB
stdin
Standard input is empty
stdout
m[6] = 1
m[2] = 5
m[4] = 6
m[1] = 10