C++ ispunct()

ispunct() 原型

int ispunct(int ch);

ispunct() 函数根据当前的 C 语言环境检查 ch 是否为标点符号字符。默认情况下,标点符号字符是 !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~。

如果 ch 的值不能表示为 unsigned char 或不等于 EOF,则 ispunct() 的行为是未定义的。

它定义在 <cctype> 头文件中。

ispunct() 参数

ch: 要检查的字符。

ispunct() 返回值

如果 ch 是标点符号字符,ispunct() 函数返回非零值,否则返回零。

示例:ispunct() 函数如何工作

#include <cctype>
#include <iostream>

using namespace std;

int main()
{
    char ch1 = '+';
    char ch2 = 'r';

    ispunct(ch1) ? cout << ch1 << " is a punctuation character" : cout << ch1 << " is not a punctuation character";
    cout << endl;
    ispunct(ch2) ? cout << ch2 << " is a punctuation character" : cout << ch2 << " is not a punctuation character";

    return 0;
}

运行程序后,输出将是

+ is a punctuation character
r is not a punctuation character
你觉得这篇文章有帮助吗?

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战