Answers for "Print frequencies of individual words in a string"

C++
0

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
Posted by: Guest on April-16-2021

Code answers related to "Print frequencies of individual words in a string"

Browse Popular Code Answers by Language