iswpunct() 函数在 C++ STL 中
在本文中,我们将讨论 C++ 中的 iswpunct() 函数,它的语法、工作原理和返回的值。
iswpunct() 函数是 C++ 中的内置函数,定义在 <cwctype> 头文件中。该函数检查传入的宽字符是否为标点字符。此函数是 ispunct() 的宽字符等效项,这意味着它与 ispunct() 的工作方式相同,区别在于它支持宽字符。因此,此函数检查传入的参数是否是标点字符,如果是,则返回任何非零整数值(真),否则,它将返回零(假)
标点字符如下
! @ # $ % ^ & * ( ) “ ‘ , . / ; [ { } ] : ?语法
int iswpunct(wint_t ch);
该函数只接受一个参数,即要检查的宽字符。参数被转换为 wint_t 或 WEOF。
wint_t 存储整数类型的数据。
返回值
该函数返回一个整数值,该值可以是 0(假)或任何非零值(真)。
示例
#include <iostream>
#include <cwctype>
using namespace std;
int main() {
wint_t a = '.';
wint_t b = 'a';
wint_t c = '1';
iswpunct(a)?cout<<"\nIts Punctuation character":cout<<"\nNot Punctuation character";
iswpunct(b)?cout<<"\nIts Punctuation character":cout<<"\nNot Punctuation character";
iswpunct(c)?cout<<"\nIts Punctuation character":cout<<"\nNot Punctuation character";
}输出
如果我们运行以上代码,它将生成以下输出:
Its Punctuation character Not Punctuation character Not Punctuation character
示例
#include <iostream>
#include <cwctype>
using namespace std;
int main () {
int i, count;
wchar_t s[] = L"@tutorials, point!!";
count = i = 0;
while (s[i]) {
if(iswpunct(s[i]))
count++;
i++;
}
cout<<"There are "<<count <<" punctuation characters.\n";
return 0;
}输出
如果我们运行以上代码,它将生成以下输出:
There are 4 punctuation characters.
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言
C++
C#
MongoDB
MySQL
Javascript
PHP