定义一个char 类型的数组不就行了
char a[30] = {"d","g",....}
或者如下
#include<iostream>
#include<stdio.h>
using namespace std;
int letter=0,space=0,digit=0,other=0;
main()
{char c;
cout<<"请输入字符"<<'\n';
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letter++;
else if (c==' ')space++;
else if(c>='0'&&c<='9')
digit++;
else other++;
}
cout<<"letter is"<<' '<<letter<<'\n';
cout<<"space is"<<' '<<space<<'\n';
cout<<"digit is"<<' '<<digit<<'\n';
cout<<"other is"<<' '<<other<<'\n';
return 0;
}