输入一串字符串,判断里面有多少大写字母,小写字母,数字,空格和特殊字符
#include <iostream>
#include <string>
void main()
{
std::string str;
std::cout << "请输入一段字符串";
getline(std::cin,str);
int lower = 0;
int upper = 0;
int number = 0;
int space = 0;
int other = 0;
for (int i =0;i < str.length();i++)
{
const char* cstr = str.c_str();
if (isupper(cstr[i]))
{
upper++;
}
else if (islower(cstr[i]))
{
lower++;
}
else if (isdigit(cstr[i]))
{
number++;
}
else if (isspace(cstr[i]))
{
space++;
}
else
{
other++;
}
}
std::cout << "大写字母个数:" << upper << "\n" << "小写字母个数:" << lower << "\n" << "数字个数:" << number << "\n" << "空格个数:" << space << "\n" << "特殊字符个数:" << other << "\n";
}