std::iscntrl

Header: <cctype>

Checks if the given character is a control character as classified by the currently installed C locale. In the default, “C” locale, the control characters are the characters with the codes 0x00-0x1F and 0x7F.

# Declarations

int iscntrl( int ch );

# Parameters

# Return value

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

# Notes

Like all other functions from , the behavior of std::iscntrl 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 <clocale>
#include <iostream>
 
int main()
{
    unsigned char c = '\x94'; // the control code CCH in ISO-8859-1
 
    std::cout << "iscntrl(\'\\x94\', default C locale) returned "
              << std::boolalpha << !!std::iscntrl(c) << '\n';
 
    std::setlocale(LC_ALL, "en_GB.iso88591");
    std::cout << "iscntrl(\'\\x94\', ISO-8859-1 locale) returned "
              << !!std::iscntrl(c) << '\n';
 
}

# See also