提示并输入一个字符串,统计该字符中大写、小写字母个数、数字个数、空格个数以及其他字符个数
要求使用C++风格字符串完成
#include <iostream>using namespace std;int main()
{string str;cout << "请输入一个字符串:" << endl;getline(cin, str);int size = str.size();int DaXie = 0, Xiaoxie = 0, Num = 0, Space = 0, Other = 0;for(int i=0;i < size;i++){if(str.at(i) <= 'Z' && str.at(i) >= 'A'){DaXie++;}else if(str.at(i) <= 'z' && str.at(i) >= 'a'){Xiaoxie++;}else if(str.at(i) <= '9' && str.at(i) >= '0'){Num++;}else if(str.at(i) == ' '){Space++;}else{Other++;}}cout << "大写字母个数:" << DaXie << endl;cout << "小写字母个数:" << Xiaoxie << endl;cout << "数字个数:" << Num << endl;cout << "空格个数:" << Space << endl;cout << "其他字符个数:" << Other << endl;