1.要求
2.做法
3.代码
int main() {
string str;
getline(cin, str);
int whitespace = 0;
int digits = 0;
int chars = 0;
int others = 0;
int i = 0;
char* src1=&str[0];
while(*src1 !='\0') {
if (isalpha(str[i])) {
chars++;
}
else if (isspace(str[i])) {
whitespace++;
}
else if (isdigit(str[i])) {
digits++;
}
else {
others++;
}
src1++;
i++;
}
cout << "chars : " << chars
<< " whitespace : " << whitespace
<< " digits : " << digits
<< " others : " << others << endl;
return 0;
}