📜  C++ iscntrl()(1)

📅  最后修改于: 2023-12-03 15:13:54.401000             🧑  作者: Mango

C++ iscntrl()
Introduction

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.

Function Syntax

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.

Example Usage

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.

Markdown Code Snippet
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:

  • The iscntrl() function returns a non-zero value if the character is a control character.
  • If the character is not a control character, the function returns zero.

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.