#include <iostream> using namespace std; int main() { char content; int
letter = 0, space = 0, number = 0, else_content = 0; cout << "请输入一行字符:" <<
endl; while ((content = getchar()) && (content != '\n')) { if
((content >= 'a' && content <= 'z') || (content >= 'A' && content <= 'Z'))
letter += 1; else if (content >= '0' && content <= '9')
number += 1; else if (content == ' ') space += 1;
else else_content += 1; } cout << "英文字母个数为:" << letter
<< endl; cout << "空格个数为:" << space << endl; cout << "数字个数为:" << number
<< endl; cout << "其他字符个数为:" << else_content << endl; return 0; }
假如用python的话,可以遍历输入的字符串,用C++需要用到getchar()函数,getchar函数可以返回输入每个字符的ASCII值,putchar函数输出单个字符,也可以输出ASCII值对应的字符