//刚才误解你意思了。
//判断字母和数字cctype函数里有专门判断的函数。
#include
#include
using namespace std;
int main()
{
string a;
getline(cin,a);
int kongge=0;//空格个数
int zimu=0;//字母数字,必须是英文字母
int shuzi=0;//数字
for(int i=0;i!=a.size ();i++)
{
if(a[i]==' ')kongge++;
else if((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z'))zimu++;
else if(a[i]>='0'&&a[i]<='9')shuzi++;
}
cout<
return 0;
}
#include
main()
{
char c;
int letters=0,space=0,degit=0,other=0;
printf("请输入一行字符:\n");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>'A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
other++;
}
printf("其中:字母数=%d 空格数=%d 数字数=%d 其它字符数=%d\n",letters,space,
digit,other);
}
6.3
#include
using namespace std;
void main()
{
int n, i,k=0,t=0,j=0,q=0;
char a[100];
cout<<"请输入一行字符";
gets(a);
n=strlen(a);
for(i=0;i
if((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z'))
k=k+1;
else
if(a[i]>='0'&&a[i]<='9')
t=t+1;
else
if(a[i]==' ')
j=j+1;
else
q=q+1;
}
cout<<"英文字母有"<}