I was trying to solve a particular problem from c++ primer book regarding maps & sets in which I have to make a map container which works as a word counter but I have to ignore punctuation & cases. For example, “example.” “example,” and “Example” should all increment the same key in the word counter.
Basic code of the map is as follows :-
map<string, size_t> word_count;
string word;
while (cin >> word)
++word_count[word];
for (const auto &a : word_count)
cout <<a.first<<" occurs "<<a.second<<((a.second>1) ? " times" : " time");
So what should I add into this code so that my word counter would ignore cases & punctuation on same words?