fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. struct Key
  8. {
  9. int value, id;
  10. };
  11.  
  12. bool operator <(const Key& a, const Key& b)
  13. {
  14. return a.value < b.value;
  15. }
  16.  
  17. int main(int argc, const char * argv[])
  18. {
  19. multimap<Key,int> m;
  20. m.insert(make_pair(Key{1,1},11));
  21. m.insert(make_pair(Key{1,2},12));
  22. m.insert(make_pair(Key{1,3},13));
  23. m.insert(make_pair(Key{2,1},21));
  24. m.insert(make_pair(Key{2,2},22));
  25. m.insert(make_pair(Key{2,3},23));
  26.  
  27. for(auto x: m)
  28. cout << x.first.value << ":" << x.first.id
  29. << " " << x.second << endl;
  30. }
  31.  
Success #stdin #stdout 0s 4372KB
stdin
Standard input is empty
stdout
1:1   11
1:2   12
1:3   13
2:1   21
2:2   22
2:3   23