我的程序是这样的:
#include<iostream.h>
#include<ctype.h>
int main()
{
char ch;
int aCnt=0,eCnt=0,iCnt=0,oCnt=0,uCnt=0;
int consonantCnt=0,ffCnt=0,flCnt=0,fiCnt=0;
while(cin.get(ch))
switch(ch)
{
case'a':
case'A':
++aCnt ;
break;
case'e':
case'E':
++eCnt ;
break;
case'i':
case'I':
++iCnt ;
break;
case'o':
case'O':
++oCnt ;
break;
case'u':
case'U':
++uCnt ;
break;
case'f':
++consonantCnt;
cin.get(ch);
switch(ch)
{
case'f':
++consonantCnt;
++ffCnt;
break;
case'i':
++consonantCnt;
++iCnt;
++fiCnt;
break;
case'l':
++consonantCnt;
++flCnt;
break;
default:cin.putback(ch);
break;
}
default:if(isalpha(ch))
++consonantCnt;
break;
} //这样统计ff,fi,fl的个数行吗????为什么输入fi,fl后都统计不出来
cout<<"a:"<<aCnt<<endl;
cout<<"e:"<<eCnt<<endl;
cout<<"i:"<<iCnt<<endl;
cout<<"o:"<<oCnt<<endl;
cout<<"u:"<<uCnt<<endl;
cout<<"consonant:"<<consonantCnt<<endl;
cout<<"ff:"<<ffCnt<<endl;
cout<<"fi:"<<ffCnt<<endl;
cout<<"fl:"<<ffCnt<<endl;
return 0;
}
还有个问题就是这个程序是无限的让输入值,输入回车键或空格程序不法执行!
cin 这样输入行吗??