C++ cctype isspace() Function
Example
Check if a space, a newline and a letter are whitespace characters:
cout << (isspace(' ') ? "Yes" : "No") << "\n";
cout << (isspace('\n') ? "Yes" : "No") << "\n";
cout << (isspace('A') ? "Yes" : "No");
Definition and Usage
The isspace() function checks if a character is a whitespace character.
Whitespace characters are the space ' ', the tab '\t', the newline '\n', and a few less common ones, like the carriage return '\r'. It returns a non-zero number (true) if it is, and 0 (false) if it is not.
The isspace function is defined in the <cctype> header file.
Tip: See how to remove all whitespace from a string in How To Remove Whitespace.
Syntax
int isspace(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 whitespace character, otherwise 0 (false). |
|---|
Related Pages
Read more about strings in our Strings Tutorial.