increment map using ++ operator

后端 未结 1 1950
小蘑菇
小蘑菇 2021-01-31 01:46

I have a map to count the occurrence of words in a file. I am reading words from the file, and each time I read a word I want to do this:

map[word]++; //(where m         


        
相关标签:
1条回答
  • 2021-01-31 02:15

    will my program crash because the int in my map is unitialized?

    No; if the element with key word doesn't exist, the element will be created and value initialized. A value-initialized int has a value of 0.

    0 讨论(0)
提交回复
热议问题