Here are some helpful and most used Character Functiions in C++.
| Function |
Description |
Example |
| isdigit(c) |
Returns true if c is a digit. |
isdigit('4') is true isdigit('z') is false |
| isalpha(c) |
Returns true if c is a letter. |
isalpha('y') is true isdigit('6') is false |
| isalnum(c) |
Returns true if c is a letter or a digit. |
isalnum('4') is true isalnum('z') is true |
| islower(c) |
Returns true if c is a lowercase letter. |
islower('w') is true islower('W') is false |
| isupper(c) |
Returns true if c is a uppercase lettert. |
isupper('Y') is true isupper('y') is false |
| isspace(c) |
Returns true if c is a whitespace character. |
isspace('\t') is true isspace('r') is false |
| isprint(c) |
Returns true if c is a printable character inclding space ' '. |
isprint('4') is true isprint(' ') is true |
| isgraph(c) |
Returns true if c is a printable character excluding space. |
isgraph('z') is true isgraph(' ') is false |
| ispunct(c) |
Returns true if c is a printable character other than a digit, letter or space. |
ispunct('*') is true ispunct('z') is false ispunct(',') is true |
| iscntrl(c) |
Returns true if c is a control character such as '\n','\f','\v','\a', and '\b'. |
iscntrl('\n') is true iscntrl('*') is false iscntrl('\f') is true |
| *NOTE: You must include this import: #include <cctype> |
| Case Conversion Functions |
| Function |
Description |
Example |
| tolower(c) |
Returns the lowercase equivalent of c, if c is an uppercase letter. Otherwise returns the orginal c. |
tolower('B') returns 'b' tolower('b') returns 'b' tolower('\n') returns '\n' |
| toupper(c) |
Returns the uppercase equivalent of c, if c is an lowercase letter. Otherwise returns the orginal c. |
toupper('B') returns 'B' toupper('b') returns 'B' toupper('\n') returns '\n' |
| *NOTE: You must include this import: #include <cctype> |