程序如下:
#include<iostream>
#include<string>
using namespace std;
int main()
{
char word[20];
int count=0;
cout<<"Enter words,stop with done:";
cin>>word;
while(strcmp(word,"done")) //若str1==str2,则返回零;若str1>str2,则返回正数;若str1<str2,则返回负数。
{
count++;
cin>>word;
}
cout<<"You entered a total of "<<count<<" words"<<endl;
return 0;
}
对于while循环体中部分不是很理解,cin是怎么判断下一个字符串的?cin不是会忽略空格吗?