count words string c++ code example
Example: count word c++
int countWords(string str)
{
// Input: Go Go Ganger
// Output: 3
stringstream s(str);
string word; // to store individual words
int count = 0;
while (s >> word)
count++;
return count;
}