另外4楼的程序出现的问题也是比较多的根本就不能运行!
应该写为:
#include<iostream.h>
#include<ctype.h>
#include<conio.h> // for need of getch();
#include<fstream>
#include<cstdlib> // for need of EXIT_FAILURE
using namespace std;
int main()
{
char ch;
int aCnt=0,eCnt=0,iCnt=0,oCnt=0,uCnt=0;
int consonantCnt=0,ffCnt=0,flCnt=0,fiCnt=0;
ifstream ins;
ins.open("myLetter.txt");
if (ins.fail())
{
cerr<<"***Error:Cannot open myLetter.txt for input."<<endl;
return 0;
}
ins.get(ch);
while (!ins.eof())
{
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;
ins.get(ch);
switch(ch)
{
case'f':
++consonantCnt;++ffCnt;
break;
case'i':
++iCnt;++fiCnt;
break;
case'l':
++consonantCnt;++flCnt;
break;
}
break;
default: ++consonantCnt;
break;
}
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;
break;
}
return 0;
}
该程序因为是带文件存储的所以应在相应的MyProjects文件夹中加一个名为myLetter.txt的文件内容可以是一些写好的字符串。如:F:\Program Files\Microsoft Visual Studio\MyProjects\myLetter.txt内容为:“hsdklfdjfjsdfksfiweoppsadoppqfipsakffsdajkfjdlsalfka”就可以了。