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;
}
CodePudding user response:
You'll have to pass EOF. To pass EOF you can use Ctrl z in Windows and Ctrl d in Unix systems.
Another solution is to type a specific word to exit. Eg:
while ((cin>>str) != "exit")
.