用C++实现输出一字符串的单词数
来源:百度知道 编辑:UC知道 时间:2024/05/12 17:40:52
输入一串字符,编个程序来输出有多少个单词。
程序如下:
#include<iostream.h>
void main()
{
int n(0);
char sentence,cha;
cout<<"please enter a sentence:";
cin>>sentence;
while(cha=' ')
{
n++;
}
{
if(cha='#')
n+=1;
}
cout<<"the amout of the words of the sentence is:"<<n<<endl;
}