fork(1) download
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. map<double,string> myMap;
  9. myMap[10.01] = "A";
  10. myMap[14.62] = "B";
  11. myMap[16.33] = "C";
  12. myMap[45.23] = "D";
  13. myMap[0.23] = "E";
  14.  
  15. map<double,string>::iterator it;
  16. for(it = myMap.begin(); it != myMap.end() ; it++){
  17. cout << it->first << " => " << it->second << endl;
  18. }
  19.  
  20. map<double,string>::iterator firstAbove_1;
  21. firstAbove_1 = myMap.lower_bound(15.); //
  22. cout << "first greater than 15 is " << firstAbove_1->second << '\n';
  23.  
  24. map<double,string>::iterator firstAbove_2;
  25. firstAbove_2 = myMap.upper_bound(15.);
  26. cout << "first greater than 15 is " << firstAbove_2->second << '\n';
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
0.23 => E
10.01 => A
14.62 => B
16.33 => C
45.23 => D
first greater than 15 is C
first greater than 15 is C