#include<iostream.h>
#include<string.h>
class WORD{
char str[80];
int c;
public:
WORD(char *s)
{
c=0;
strcpy(str,s);
}
void process() //统计单词个数函数
{
char *p=str;
while(*p)
{
while(*p==' '&&*p) p++;
while(*p!=' '&&*p) p++;c++;
}
}
void print()
{
cout<<str<<endl;
cout<<"c="<<c<<endl;
}
};
void main()
{
WORD w("She is a nice girl");
w.process();
w.print();
}
温馨提示:答案为网友推荐,仅供参考