#include <iostream>
#include <string.h>
using namespace std;
int main()
{
cout << "输入一个字符串:";
string str;
getline(cin,str);
cout << "字符个数是" << str.size() <<endl;
int m=0,n=0,num=0,space=0,other=0;
for(int i=0;i< str.size();i++)
{
if(int(str.at(i))>=97&&int(str.at(i))<=122)
n++;
else if(int(str.at(i))>=65&&int(str.at(i))<=90)
m++;
else if(int(str.at(i))>=48&&int(str.at(i))<=57)
num++;
else if(int(str.at(i))==32)
space++;
else
other++;
}
cout << "大写字母个数=" << m << " " << "小写字母个数=" << n << " " << "数字个数=" << num << " " << "空格个数=" << space << " " << "其他=" << other << endl;
return 0;
}
运行结果