Print frequencies of individual words in a string code example
Example: Print frequencies of individual words in a string
void printFrequency(string str)
{
map<string, int> FW;
stringstream s(str);
string Word;
while (s >> Word)
FW[Word]++;
for (auto m : FW)
cout << m.first << " -> " << m.second << "\n";
}
// Input: One Two Three One Three
// Output One -> 2
// Three -> 2
// Two -> 1