C++ cctype Library
C++ cctype Functions
The <cctype> library has functions that check or change a single character. For example, you can check if a character is a digit, or change a letter to uppercase.
The functions that start with is return an int: a non-zero number (true) if the character matches, and 0 (false) if it does not. The true value is not always 1, so use the result in an if statement, and do not print it directly.
tolower() and toupper() also return an int. Store the result in a char variable to get a character.
| Function | Description |
|---|---|
| isalnum() | Checks if a character is a letter or a digit |
| isalpha() | Checks if a character is a letter |
| isblank() | Checks if a character is a blank character (a space or a tab) |
| iscntrl() | Checks if a character is a control character, like a newline or a tab |
| isdigit() | Checks if a character is a digit (0-9) |
| isgraph() | Checks if a character is a graphical character (any printable character except the space) |
| islower() | Checks if a character is a lowercase letter |
| isprint() | Checks if a character is printable (a letter, digit, punctuation mark or space) |
| ispunct() | Checks if a character is a punctuation character, like ! or ? |
| isspace() | Checks if a character is a whitespace character, like a space, a tab or a newline |
| isupper() | Checks if a character is an uppercase letter |
| isxdigit() | Checks if a character is a hexadecimal digit (0-9, a-f or A-F) |
| tolower() | Converts a character to lowercase |
| toupper() | Converts a character to uppercase |
Related Pages
C++ How To Count Digits in a String
C++ How To Count Vowels in a String
C++ How To Remove Whitespace from a String