cctype 头文件定义函数实例

来源:网络时间:2011-04-25 15:03:27

    cctype 头文件所包含的函数主要用来测试字符值,以下是随便找的一个表,但是对于初学者来说,怎么用呢,自己上机操作解决,后两个返回的是int型,确实很意外,强制转换一下,很简单。

    isalnum(c) 假如c是字母或数字,则为true

    isalpah(c) 假如c是字母,则为true

    iscntrl(c) 假如c是控制字符,则为true

    isdigit(c) 假如c是数字,则为true

    isgraph(c) 假如c不是空格,则为true

    islower(c) 假如c是小写字母,则为true

    isprint(c) 假如c是可打印的字符,则为true

    ispunct(c) 假如c是标点符号,则为true

    isspace(c) 假如c是空白字符,则为true

    isupper(c) 假如c是大写字母,则为true

    isxdigit(c) 假如c是十六进制数,则为true

    tolower(c) 假如c是大写字母,则返回小写字母形式,否则返回c。

    toupper(c) 假如c是小写字母,则返回大些字母形式,否则返回c。

    我演示第一个和最后一个,比较有代表性。

    #include <iostream> #include <cctype> using namespace std; int main() {        char c;         c='d';     if(isalnum(c))     {         cout《c《" is an alpha or number";     }     else         cout《c《" is an not alpha or number";   } 输出结果如下图:#include <iostream> #include <cctype> using namespace std; int main() {        char c;     c='D';     cout《char(tolower(c));  }

    tolower()函数返回的是一个整数类型,所以如果不重载这个函数的话就通过类型转换来实现正确的输出,注意看哦

文章内容来源于网络,不代表本站立场,若侵犯到您的权益,可联系我们删除。(本站为非盈利性质网站) 联系邮箱:rjfawu@163.com