Draft 2002-02-20

<cctype>

The <cctype> header (from the C standard <ctype.h> header) declares a number of functions for testing and mapping narrow character types. For working with wide characters, see <cwctype>.

All the functions take int parameters, but the value of the parameter must be an unsigned char. Most programs work with ordinary char, so you must cast the parameters and some of the return types. For example:

char c;
if (std::isalnum(static_cast<unsigned char>(c)))
...
c = static_cast<char>(
      std::tolower(static_cast<unsigned char>(c)));

The only other value that is permitted is EOF.

These functions get their information from the current locale. The "C" locale is the only one with behavior that is defined in the standard; all other locales can define these functions to include or exclude different characters. One requirement is that isalpha, iscntrl, isdigit, ispunct and the space character (' ') are mutually exclusive.

See the <locale> header for more information about character types and locales.

isalnum function

Syntax

int isalnum(int c)

Description

The isalnum function returns true if c is alphanumeric, that is, it returns isalpha(c) || isnumeric(c).

isalpha function

Syntax

int isalpha(int c)

Description

The isalpha function returns true if c is alphabetic. In the "C" locale, this includes only the characters for which islower(c) or isupper(c) is true. For other locales, other characters might be alphabetic.

iscntrl function

Syntax

int iscntrl(int c)

Description

The iscntrl function returns true if c is a control character. In the 7-bit ASCII character set, the control characters are '\0' to '\x1F' and '\x7F'; other implementations might have different control characters. By definition, a control character is any character that is not a printable character (isprint).

isdigit function

Syntax

int isdigit(int c)

Description

The isdigit function returns true if c is a decimal digit character, that is, '0' through '9' , regardless of locale.

isgraph function

Syntax

int isgraph(int c)

Description

The isgraph function returns true if c is any printing character (isprint) except space (' '). The set of printing characters varies with locale.

islower function

Syntax

int islower(int c)

Description

The islower function returns true if c is a lowercase letter. In the "C" locale, the characters 'a' through 'z' are lowercase; different locales can define other lowercase characters.

isprint function

Syntax

int isprint(int c)

Description

The isprint function returns true if c is a printing character, including space (' '), according to the locale. Informally, a printing character is one that occupies space on a display device.

ispunct function

Syntax

int ispunct(int c)

Description

The ispunct function returns true for a punctuation character, that is, any printable character (isprint) other than space (' ') and alphanumeric characters (isalnum).

isspace function

Syntax

int isspace(int c)

Description

The isspace function returns true if c is a white space character. In the "C" locale, the space (' '), form feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v') characters are white space, but back space ('\b') is not. Different locales can define other white space characters.

isupper function

Syntax

int isupper(int c)

Description

The isupper function returns true if c is an uppercase letter. In the "C" locale, the characters 'A' through 'A' are uppercase; different locales can define other uppercase characters

isxdigit function

Syntax

int isxdigit(int c)

Description

The isxdigit function returns true if c is any hexadecimal digit character, that is, '0' through '9', 'a' through 'f', or 'A' though 'F', regardless of locale.

tolower function

Syntax

int tolower(int c)

Description

The tolower function converts uppercase characters to lowercase. If c is uppercase (that is, isupper(c) returns true), tolower returns the corresponding lowercase character (for which islower returns true), if there is such a character. Otherwise it returns c.

toupper function

Syntax

int toupper(int c)

Description

The touoper function converts lowercase characters to uppercase. If c is lowercase (that is, islower(c) returns true), toupper returns the corresponding uppercase character (for which isupper returns true), if there is such a character. Otherwise it returns c.