0
点赞
收藏
分享

微信扫一扫

cctype头文件中定义的函数

    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。

范例:

统计string字符串中标点符号的个数:

#include <cctype>

int main()
{
string str("  ????ni hao ma");
string::size_type ct_count = 0;
for (string::size_type st = 0; st != str.size(); st++)
{
if ( ispunct(str[st]) )      //读出字符串的符号的个数
{
ct_count++;
}
}
cout << ct_count << endl;
return 0;
}


举报

相关推荐

0 条评论