习题6.8
#include <iostream>
#include <string>
using namespace std;
int main(){
string str;
cout << "请输入一个字符串:" << endl;
getline(cin, str);
int n,capital=0, lowercase=0, space=0, figure=0,other=0;
n = size(str);
for (int i = 0; i < n; i++) {
if (47 < (int)str[i] && (int)str[i] < 58)figure++;
else if (64 < (int)str[i] && (int)str[i] < 91)capital++;
else if (96 < (int)str[i] && (int)str[i] < 123)lowercase++;
else if ((int)str[i] == 32)space++;
else other++;
}
cout << "该字符串中:" << endl;
cout << "大写字母有" << capital << "个,";
cout << "小写字母有" << lowercase << "个,";
cout << "空有" << space << "个,";
cout << "数字有" << figure << "个,";
cout << "其他字符有" << other << "个。" << endl;
return 0;
}