std::isspace

Header: <cctype>

Checks if the given character is whitespace character as classified by the currently installed C locale. In the default locale, the whitespace characters are the following:

# Declarations

int isspace( int ch );

# Parameters

# Return value

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

# Notes

Like all other functions from , the behavior of std::isspace 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 <iomanip>
#include <iostream>
 
int main(void)
{
    std::cout << std::hex << std::setfill('0') << std::uppercase;
    for (int ch{}; ch <= UCHAR_MAX; ++ch)
        if (std::isspace(ch))
            std::cout << std::setw(2) << ch << ' ';
    std::cout << '\n';
}

# See also