C++ 标准库 cctype

C++ 语言下,一般作为判断条件进行操作

头文件:#include
说明:字符处理库

功能一:字符测试

  • 函数原型均为:int isXXX(int ch )
  • 参数均为int ,即在ASCII 码的范围内进行字符处理[0-127]
    isalnum() 当字母或数值型字符返回真值
    isalpha() 当字母字符时返回真值
    iscntrl() 当控制字符时返回真值 (14 - 31)
    isblank() 当空白字符返回真值
    isdigit() 当是数字字符返回真值
    isgraph() 当非空格可打印字符返回真值
    islower() 当是小写字母字符返回真值
    isprint() 当是可打印字符返回真值
    ispunct() 当标点字符返回真值 isgraph() && !isalnum()
    isspace()当是空格返回真值
    isuper() 当是大写字母字符,返回真值
    isxdigit() 当是16进制字符,返回真值
C++ 标准库 cctype_第1张图片
C documentation.png

功能二:字符映射

  • 函数原型:int istoXXX(int)
  • 对参数进行检测,符合情况进行转换
    tolower() 将字符转换为小写字符
    toupper() 将字符转换为大写字符

C++ 中cctype 的头文件声明如下

// -*- C++ -*-
//===---------------------------- cctype ----------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP_CCTYPE
#define _LIBCPP_CCTYPE

/*
    cctype synopsis

namespace std
{

int isalnum(int c);
int isalpha(int c);
int isblank(int c);  // C99
int iscntrl(int c);
int isdigit(int c);
int isgraph(int c);
int islower(int c);
int isprint(int c);
int ispunct(int c);
int isspace(int c);
int isupper(int c);
int isxdigit(int c);
int tolower(int c);
int toupper(int c);

}  // std
*/

#include <__config>
#include 
#if defined(_LIBCPP_MSVCRT)
#include "support/win32/support.h"
#include "support/win32/locale_win32.h"
#endif // _LIBCPP_MSVCRT

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

#undef isalnum
using ::isalnum;
#undef isalpha
using ::isalpha;
#undef isblank
using ::isblank;
#undef iscntrl
using ::iscntrl;
#undef isdigit
using ::isdigit;
#undef isgraph
using ::isgraph;
#undef islower
using ::islower;
#undef isprint
using ::isprint;
#undef ispunct
using ::ispunct;
#undef isspace
using ::isspace;
#undef isupper
using ::isupper;
#undef isxdigit
using ::isxdigit;
#undef tolower
using ::tolower;
#undef toupper
using ::toupper;

_LIBCPP_END_NAMESPACE_STD

#endif  // _LIBCPP_CCTYPE

你可能感兴趣的:(C++ 标准库 cctype)