提示并输入一个字符串,统计该字符中大写,小写字母个数,数字个数,空格个数以及其他字符个数,要求使用C++风格字符串完成
#include <iostream>using namespace std;int main()
{string str;int A=0,a=0,num=0,backspace=0,other=0;cout << "请输入一个字符串:" ;getline(cin, str);for(int i = 0;i < str.size(); i++ ){if((int)'A' <= str[i] && str[i] <= (int)'Z'){A++;}else if(97 <= str[i] && str[i] <= 123){a++;}else if('0' <= str[i] && str[i] <= '9'){num++;}else if(str[i] == '\40'){backspace++;}else{other++;}}cout << "大写有:" << A << "个,小写有:" << a << "个,数字有:" << num << "个,空格有:" << backspace << "个,其他字符有:" << other << "个。" <<endl;return 0;
}