C++ cctype isdigit() Function
Example
Check if a character is a digit:
char c = '8';
if (isdigit(c)) {
cout << c << " is a digit";
} else {
cout << c << " is not a digit";
}
Definition and Usage
The isdigit() function checks if a character is a digit, from 0 to 9.
It returns a non-zero number (true) if it is, and 0 (false) if it is not. Only the characters 0 to 9 are digits. The minus sign - and the decimal point . are not digits.
The isdigit function is defined in the <cctype> header file.
Tip: See how to count the digits in a string in How To Count Digits in a String.
Syntax
int isdigit(int c);
Parameter Values
| Parameter | Description |
|---|---|
| c | Required. The character to check. |
Technical Details
| Returns: | An int value. Non-zero (true) if the character is a digit, otherwise 0 (false). |
|---|
Related Pages
Read more about strings in our Strings Tutorial.