首页 > 文章列表 > 在C/C++中,iswpunct()函数的作用是判断一个宽字符是否为标点符号

在C/C++中,iswpunct()函数的作用是判断一个宽字符是否为标点符号

C/C 标点符号 iswpunct()
419 2023-08-25

函数iswpunct()用于检查传递的宽字符是否为标点符号。如果不是标点符号,则返回零,否则返回非零值。它在“cwctype”头文件中声明。

以下是iswpunct()的语法:

int iswpunct(wint_t character);

这是iswpunct()的一个示例

示例

#include<cwctype>
#include<stdio.h>
using namespace std;
int main() {
   wint_t a = '!';
   wint_t b = 'a';
   if(iswpunct(a))
   printf("The character is a punctuation.");
   else
   printf("nThe character is not a punctuation.");
   if(iswpunct(b))
   printf("nThe character is a punctuation.");
   else
   printf("nThe character is not a punctuation.");
   return 0;
}

输出

The character is a punctuation.
The character is not a punctuation.

在上面的程序中,两个宽字符被声明为a和b。检查传递的字符是否为标点符号。

wint_t a = '!';
wint_t b = 'a';
if(iswpunct(a))
printf("The character is a punctuation.");
else
printf("nThe character is not a punctuation.");
if(iswpunct(b))
printf("nThe character is a punctuation.");
else
printf("nThe character is not a punctuation.");