fork download
  1. #include <iostream>
  2. #include <map>
  3.  
  4. int main (void) {
  5. std::map<char,char> mymap;
  6. std::map<char,char>::iterator it;
  7.  
  8. mymap['a'] = 'A'; mymap['b'] = 'B'; mymap['c'] = 'C';
  9. mymap['d'] = 'D'; mymap['e'] = 'E'; mymap['f'] = 'F';
  10. mymap['g'] = 'G'; mymap['h'] = 'H'; mymap['i'] = 'I';
  11.  
  12. it = mymap.find ('b'); // by iterator (b), leaves acdefghi.
  13. mymap.erase (it);
  14.  
  15. it = mymap.find ('e'); // by range (e-i), leaves acd.
  16. mymap.erase (it, mymap.end());
  17.  
  18. mymap.erase ('a'); // by key (a), leaves cd.
  19.  
  20. mymap.erase ('z'); // invalid key (none), leaves cd.
  21.  
  22. for (it = mymap.begin(); it != mymap.end(); it++)
  23. std::cout << (*it).first << " => " << (*it).second << '\n';
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 5664KB
stdin
Standard input is empty
stdout
c => C
d => D