std::isdigit

Header: <cctype>

Checks if the given character is one of the 10 decimal digits: (0123456789).

# Declarations

int isdigit( int ch );

# Parameters

# Return value

Non-zero value if the character is a numeric character, zero otherwise.

# Notes

isdigit and isxdigit are the only standard narrow character classification functions that are not affected by the currently installed C locale. although some implementations (e.g. Microsoft in 1252 codepage) may classify additional single-byte characters as digits.

Like all other functions from , the behavior of std::isdigit is undefined if the argument’s value is neither representable as unsigned char nor equal to EOF. To use these functions safely with plain chars (or signed chars), the argument should first be converted to unsigned char:

Similarly, they should not be directly used with standard algorithms when the iterator’s value type is char or signed char. Instead, convert the value to unsigned char first:

# Example

#include <cctype>
#include <climits>
#include <iostream>
 
int main(void)
{
    for (int i = 0; i <= UCHAR_MAX; ++i)
        if (std::isdigit(i))
            std::cout << static_cast<unsigned char>(i);
    std::cout << '\n';
}

# See also