fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. map<string, unsigned int> myMap;
  9.  
  10. string key = "value";
  11. map<string, unsigned int>::iterator it = myMap.find(key);
  12.  
  13. if(it == myMap.end())
  14. myMap.insert(pair<string, unsigned int> (key, 1));
  15. else
  16. {
  17. int prev_value = it->second;
  18. prev_value++;
  19. myMap.insert(pair<string, unsigned int> (key, prev_value));
  20. }
  21.  
  22. cout << "first: " << crbegin(myMap)->first << " second: " << crbegin(myMap)->second << endl;
  23. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
first: value second: 1