Solution 1 looks neat and precise...
Alternatively you may want to use the code block below which basically splits your input into individual words and then you can add your code for doing the count
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main (int argc, char * const argv[]) {
cout << "Enter the text\n";
string input;
getline(cin,input);
char *delim = " ,.-";
char* split = strtok((char *)input.c_str() , delim);
vector<string> result;
while (split != NULL) {
result.push_back(split);
split = strtok(NULL, delim);
}
return 0;
}