while (cin >> word)
++word_count.insert({word, 0}).first->second;
The code just does the same thing as ++word_count[word];
. If the word
is in map
, then increase the count of that word by 1, else insert that word into map
, set the count to 0, and increase the count by 1.