提示并输入一个字符串,统计该字符中大写、小写字母个数、数字个数、空格个数以及其他字符个数
要求使用C++风格字符串完成
?
#include <iostream>
#include<array>
using namespace std;
int main()
{
int a=0,A=0,num=0,space=0,other=0;
array<char,20> str;
array<char,20>::iterator iter;
cout << "请输入一个字符串:" << endl;
for(iter = str.begin();iter != str.end();iter++)
{
cin >> *iter;
}
for(iter = str.begin();iter != str.end();iter++)
{
if(int(*iter)>=97&&int(*iter)<=122)
{
a++;
}
else if(int(*iter)>=65&&int(*iter)<=90)
{
A++;
}
else if(int(*iter)>=48&&int(*iter)<=57)
{
num++;
}
else if(int(*iter)==32)
{
space++;
}
else
{
other++;
}
}
cout << "小写:" << a << endl;
cout << "大写:" << A << endl;
cout << "数字:" << num << endl;
cout << "空格:" << space << endl;
cout << "其他:" << other << endl;
return 0;
}