C++ cctype iscntrl() Function
Example
Check if a newline, a tab and a letter are control characters:
cout << (iscntrl('\n') ? "Yes" : "No") << "\n";
cout << (iscntrl('\t') ? "Yes" : "No") << "\n";
cout << (iscntrl('A') ? "Yes" : "No");
Definition and Usage
The iscntrl() function checks if a character is a control character. Control characters are not printed as symbols. Instead, they control the text, like a newline '\n' or a tab '\t'.
In the ASCII table, the control characters have the values 0 to 31, and 127. It returns a non-zero number (true) if it is, and 0 (false) if it is not.
The iscntrl function is defined in the <cctype> header file.
Tip: Use isprint() to check if a character can be printed.
Syntax
int iscntrl(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 control character, otherwise 0 (false). |
|---|
Related Pages
Read more about strings in our Strings Tutorial.