fork download
  1. #include <iostream>
  2. #include <utility>
  3. #include <iomanip>
  4. #include <map>
  5.  
  6. using namespace std;
  7. typedef pair<int, int> Key; //pair
  8.  
  9. void display (map <Key,float> &m) // to print maps
  10. {
  11. cout << "\tTotal size: " << m.size() << endl;
  12. map <Key,float>::iterator it;
  13. for (it = m.begin(); it != m.end(); ++it)
  14. cout << setw(10) << it->first.first << it->first.second << setw(5) << it->second << endl;
  15.  
  16. cout << endl;
  17. }
  18.  
  19. int main() {
  20.  
  21. map< Key , float> mapa; //create map
  22.  
  23. Key p1 (1, 45); //key values
  24. Key p2 (2, 20);
  25.  
  26. mapa[p1]= 25.11; //map float to keys
  27. mapa[p2]= 11.23;
  28.  
  29. display(mapa); //display map
  30.  
  31. return 0;
  32.  
  33. }
Success #stdin #stdout 0.01s 2860KB
stdin
Standard input is empty
stdout
	Total size: 2
         14525.11
         22011.23