C++ 字符处理函数(cctype头文件)

函数 说明
int isupper(char) 判断字符是否是大写字母
int islower(char) 判断字符是否是小写字母
int isalpha(char) 判断字符是否是字母
int isdigit(char) 判断字符是否是数字
int isalnum(char) 判断字符是否是字母或数字
int isspace(char) 判断字符是否是空白
int isblank(char) 判断字符是否是空格
int ispunct(char) 判断字符是否是标点符号
int isprint(char) 判断字符能否打印
int iscntrl(char) 判断字符是否是控制字符
int isgraph(char) 判断字符是否是图形字符
int tolower(char) 将字符转换为小写
int toupper(char) 将字符转换为大写
#include <iostream>
#include "cctype"

int main() {
    using std::cout;
    char c{'A'};
    cout << "A isupper:" << (isupper(c) ? "true" : "false") << char(10);
    cout << "A islower:" << (islower(c) ? "true" : "false") << char(10);
    cout << "A isalpha:" << (isalpha(c) ? "true" : "false") << char(10);
    cout << "A isdigit:" << (isdigit(c) ? "true" : "false") << char(10);
    cout << "A isalnum:" << (isalnum(c) ? "true" : "false") << char(10);
    cout << "A isblank:" << (isblank(c) ? "true" : "false") << char(10);
    cout << "A isspace:" << (isspace(c) ? "true" : "false") << char(10);
    cout << "A ispunct:" << (ispunct(c) ? "true" : "false") << char(10);
    cout << "A isprint:" << (isprint(c) ? "true" : "false") << char(10);
    cout << "A iscntrl:" << (iscntrl(c) ? "true" : "false") << char(10);
    cout << "A isgraph:" << (isgraph(c) ? "true" : "false") << char(10);
    cout << "A tolower:" << char(tolower(c)) << char(10);
    cout << "a toupper:" << char(toupper('a')) << char(10);
    return 0;
}

输出:

A isupper:true
A islower:false
A isalpha:true
A isdigit:false
A isalnum:true
A isblank:false
A isspace:false
A ispunct:false
A isprint:true
A iscntrl:false
A isgraph:true
A tolower:a
a toupper:A
posted @ 2024-03-31 00:32  予之路  阅读(35)  评论(0编辑  收藏  举报