Code:int main() { typedef std::map<string, int>::const_iterator Iter; std::map<string, int> words; // Map to store words and word counts cout << "Enter some text and press Enter followed by Ctrl+Z to end:" << endl << endl; std::istream_iterator<string> begin(cin); // Stream iterator std::istream_iterator<string> end; // End stream iterator while(begin != end ) // Iterate over words in the stream words[*begin++]++; // Increment and store a word count // Output the words and their counts cout << endl << "Here are the word counts for the text you entered:" << endl; for(Iter iter = words.begin() ; iter != words.end() ; ++iter) cout << std::setw(5) << iter->second << " " << iter->first << endl; return 0; }
The above snippet tells the number of words in a given string, it works perfectly because it is from my book
So the confusion I'm having is that in the line bold
words[*begin++]++;
This would create a new pair in the map because there are no entries in the map and the key is the string in the stream pointed by begin right? How will it create the int???? and how does it gives 0 value to the int??? it has no default constructor???