How can i calculate the number of WORDS in my string.
(note:string was filled by cin.getline command),ie.
string mystr;
cout %26lt;%26lt; "Enter the text: ";
getline(cin,mystr,'\n');
NOW,who can i calculate the number of words of my text...
please help i need this code
C++ Code in String?
hay, thats an easy one, it put the answer on my site.
www.EvilMark.co.uk
you can find it under the Programming Q%26amp;A link.
Reply:string mystr;
int i = 0;
int words = 1;
cout %26lt;%26lt; "Enter the text: ";
getline(cin,mystr,'\n');
for(i = input.find(" ", 0); i != string::npos; i = input.find(" ", i))
{
words++;
i++;
}
cout%26lt;%26lt;words;
//////////////////////////////////////... will count all the spaces plus one, and that should be all the words
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment