fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. std::map<char,int> mymap;
  9.  
  10. mymap['a']=10;
  11. mymap['b']=20;
  12. mymap['d']=40;
  13. mymap['e']=50;
  14.  
  15. for (auto ch : string("@abcdef")) {
  16. map<char,int>::const_iterator iter = mymap.lower_bound(ch);
  17. if (iter->first == ch || iter != mymap.begin()) {
  18. if (iter->first != ch) --iter;
  19. cerr << ch << ":" << iter->second << endl;
  20. } else {
  21. cerr << ch << ":" << "<default>" << endl;
  22. }
  23. }
  24. }
Success #stdin #stdout #stderr 0s 3428KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
@:<default>
a:10
b:20
c:20
d:40
e:50
f:50