C++ Character functions
Tags:
cpp
stl
Following functions are a part of the <cctype> header file
Checking character class
Note: true is 1 and false is 0 in these functions
isalpha(char c): Returns true ifcis a-z or A-Zisupper(char c): Returns true ifcis A-Z i.e. UPPERCASEislower(char c): Returns true ifcis A-Z i.e. lowercaseisdigit(char c): Returns true ifcis 0-9isxdigit(char c): Returns true ifcis hexadecimal digit (0-9 or a-f)isalnum(char c): Returns true ifcis alphanumeric (a-z or A-Z or 0-9)isblank(char c): Returns true ifcis a space or tabispunct(char c): Returns true ifcis a punctuation markisprint(char c): Returns true ifcis printable on console
Changing case
tolower(char c)- returns lowercase equivalent of input character.toupper(char c)- returns UPPERCASE equivalent of input character.
Code to print ALL punctuation characters:
char c = numeric_limits<char>::min();while (true) { if (ispunct(c)) { cout << c << " "; } c++; // Stop when it overflows back to starting value if (c == numeric_limits<char>::min()) { break; }}cout << endl;Output:
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~