isalpha() / isdigit() / isalnum() / islower() / isupper()参数为字符型变量,分别用于判断字符是否为字母 / 数字(注意是字符型) / 字母或数字 / 小写字母 / 大写字母。如果是,返回非0;如果不是,返回0。
#include<bits/stdc++.h>
using namespace std;
int main(){
char ch = 'Z';
cout << "isalpha: " << isalpha(ch) << endl;
cout << "isdigit: " << isdigit(ch) << endl;
cout << "isalnum: " << isalnum(ch) << endl;
cout << "islower: " << islower(ch) << endl;
cout << "isupper: " << isupper(ch) << endl;
return 0;
}
isalpha: 1
isdigit: 0
isalnum: 1
islower: 0
isupper: 1
--------------------------------
Process exited after 0.2368 seconds with return value 0
请按任意键继续. . .
#include<bits/stdc++.h>
using namespace std;
int main(){
char ch = '9';
cout << "isalpha: " << isalpha(ch) << endl;
cout << "isdigit: " << isdigit(ch) << endl;
cout << "isalnum: " << isalnum(ch) << endl;
cout << "islower: " << islower(ch) << endl;
cout << "isupper: " << isupper(ch) << endl;
return 0;
}
isalpha: 0
isdigit: 1
isalnum: 4
islower: 0
isupper: 0
--------------------------------
Process exited after 2.475 seconds with return value 0
请按任意键继续. . .