📅  最后修改于: 2023-12-03 15:13:54.401000             🧑  作者: Mango
C++ iscntrl()
The iscntrl()
function is a part of the <cctype>
library in C++. It is used to check whether a given character is a control character or not. Control characters are non-printable characters that are used to control output devices, such as printers or display screens.
The syntax of the iscntrl()
function is as follows:
#include <cctype>
int iscntrl(int c);
The iscntrl()
function takes an integer argument c
, which represents the character to be checked. It returns a non-zero value if the character is a control character; otherwise, it returns zero.
Here's an example usage of the iscntrl()
function:
#include <iostream>
#include <cctype>
int main() {
char ch = '\t';
if (iscntrl(ch)) {
std::cout << "The character is a control character.";
} else {
std::cout << "The character is not a control character.";
}
return 0;
}
In this example, the iscntrl()
function is used to check whether the character ch
is a control character or not. If it is a control character (such as a tab), the corresponding message will be displayed.
The `iscntrl()` function is used to check whether a character is a control character or not.
**Syntax:**
```cpp
#include <cctype>
int iscntrl(int c);
Parameters:
c
: The integer representing the character to be checked.Return Value:
iscntrl()
function returns a non-zero value if the character is a control character.Example Usage:
#include <iostream>
#include <cctype>
int main() {
char ch = '\t';
if (iscntrl(ch)) {
std::cout << "The character is a control character.";
} else {
std::cout << "The character is not a control character.";
}
return 0;
}
In the above example, the program checks whether the character ch
is a control character using the iscntrl()
function.