C++程序设计 写一个scanner,例如输入 I am a student

写一个scanner,例如输入 I am a student输出 I am a student统计单词个数4
2025-12-18 07:01:56
推荐回答(1个)
回答1:

#include
using namespace std;
int main(void)
{
char scanner[100];
int n = 0;
bool check = false;
cout<<"Enter a sentence:"< gets(scanner);
cout<<"***********************"< for(int i = 0; i {
if(scanner[i]==' ')
{
if(check)
{
cout< n++;
check = false;
}
}
else
{
check = true;
cout< }
}
cout< return 0;
} ******本程序可以输入不规范的英语句子********