一个检查单词个数的程序
#include <iostream>
#include<string>using namespace std;
void main()
{char word[20];
char temp;
int count = 0;
int i;
bool success = false;
while (success==false)
{
for (i=0; i<20; i++)
{
cin.unsetf(ios::skipws);//加这句,正常情况下,cin是不读回车的
cin>>temp;
if (temp==10)
{
success=true;
word[i]='\0';
break;
}
if (temp!=32)
word[i]=temp;
else
{
word[i]='\0';
break;
}
}
if (strcmp(word,"done"))
count++;
else
success=true;
}
cout <<count<<endl;
cin.get();
}