Hello, to extract words from sentence i use this code.
using namespace std;
int main ()
string s, word;
cout << "Enter Sentence:\n";
cout << "You entered:" << s << "\n";
s += ',';
int npos = 0;
int lpos = 0;
while ((npos = (int)s.find_first_of(",", lpos)) != string::npos )
word = s.substr(lpos, npos - lpos);
cout << word << endl;
lpos = npos + 1;
Input must be made like this (sentence): dog,cat,food,table,carrot,expert,exchange.
After last word dot.
And output should be like:
But right now, i get:
How to make, that there would be no dot "." after last word? (please write sample)
Also one more question, let say later i will need to check if word has more than 5 letters, how could i do that? i know i can't do just "if (word>5)", because word is declared as string. Please help me, thanks!