Hi all,
can you all look at this ...
I need to count the words that I got by the input stream..
why it doesn't count them.... it count just the first word...
and the first leters.... so Please tell me why it is strange...
This is the program:
#include<iostream.h>
#include<string>
int main()
{
string str1;
int j=0;
int counterwords =1;
cout<< "Please input your text string... \n";
cin>> str1;
string::iterator str1_ptr = str1.begin();
int i=0;
while (str1_ptr <= str1.end()){
i++; // increase one visit... to the loop
if (*str1_ptr == ' ')
{
counterwords++; // how many words we have here
}
str1_ptr++;// shift one to the righ.. Read one char.
}
cout<< " the number of words that you have is ...";
cout << counterwords<< endl;
cout<< " I did vist the loop for ..."<< i<< " times" << endl;
return 0;
}
GOOD LUCK!!!