Here is the Situation:
I am taking sting as a input using this:
string s;
getline (cin , s);
Now I want to fill a map of type <string, int>
. The key of this map will be individual words of the input string. The value will be storing the frequency of the word.
Example : input string - " Hello My name is OP Hello World"
Map Should be like:
Hello - 2
My - 1
name - 1
is - 1
OP - 1
World - 1
The method which i know is using string manipution to divide string into an array of seperate words.
Is there any other efficient way to split a string into array of words and fill in the map with word as a key?