I type in a sentence on the console,the rest of the statement is not executed after the while statement completes.
map<string, size_t> stringMap;
string str;
while (cin>>str)
{
++stringMap[str];
}
for (const auto &w : stringMap)
{
cout << w.first << "occurs" << w.second << "times" << endl;
}
>Solution :
You’ll have to pass EOF. To pass EOF you can use ‘ctrl+z’ in windows and ‘ctrl+d’ in unix systems.
Another solution you can do is. Type specific word to exit. Eg:
while ((cin>>str) != "exit")