C++ cctype isprint() Function
Example
Check if a letter, a space and a newline are printable characters:
cout << (isprint('A') ? "Yes" : "No") << "\n";
cout << (isprint(' ') ? "Yes" : "No") << "\n";
cout << (isprint('\n') ? "Yes" : "No");
Definition and Usage
The isprint() function checks if a character is printable. The printable characters are letters, digits, punctuation marks and the space.
It returns a non-zero number (true) if it is, and 0 (false) if it is not. Control characters, like a newline '\n', are not printable.
The isprint function is defined in the <cctype> header file.
Tip: isgraph() works the same way, but it returns false for the space.
Syntax
int isprint(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 printable, otherwise 0 (false). |
|---|
Related Pages
Read more about strings in our Strings Tutorial.