iswpunct()是C /C++中的一个函数,用于测试宽字符代码是否表示程序当前语言环境中的punct类字符。如果Wide-Character是标点符号宽字符代码,则返回非零值,否则应返回0。此函数在cwctype头文件中定义。该函数检查ch是否为标点字符。标点字符为跟随
! " # $ % & ' () * +, - . / : ; ? @ [\] ^ _ ` {|} ~
用法:
int iswpunct(ch)
参数:该函数接受单个强制参数ch,该参数指定要检查的字符。
返回值:如果字符ch是标点字符,则该函数返回非零值,否则返回零。
以下示例程序旨在说明上述函数:
// C++ program to illustrate
// the iswpunct() function
#include <bits/stdc++.h>
int main()
{
int i = 0;
int count_ = 0;
// string declaration
char string1[] = "~Hello geekforgeeks !";
char string2[count_];
// iterate in the string
while (string1[i]) {
// check if the character is
// punctuation mark or not
if (iswpunct(string1[i])) {
// store the punctuation characters
string2[count_] = string1[i];
count_++;
}
i++;
}
// prints the punctuation character
printf("The sentence contains %d punct. character :\n", count_);
for (int i = 0; i < count_; i++)
printf("%c ", string2[i]);
return 0;
}
输出:
The sentence contains 2 punct. character : ~ !
程序2:
// C++ program to illustrate
// the iswpunct() function
#include <bits/stdc++.h>
int main()
{
int i = 0;
int count_ = 0;
// string declaration
char string1[] = "@#$^gfg";
char string2[count_];
// iterate in the string
while (string1[i]) {
// check if the character is
// punctuation mark or not
if (iswpunct(string1[i])) {
// store the punctuation characters
string2[count_] = string1[i];
count_++;
}
i++;
}
// prints the punctuation character
printf("The sentence contains %d punct. character :\n", count_);
for (int i = 0; i < count_; i++)
printf("%c ", string2[i]);
return 0;
}
输出:
The sentence contains 4 punct. character : @ # $ ^
相关用法
- C++ log()用法及代码示例
- C++ div()用法及代码示例
- C++ fma()用法及代码示例
- C++ wcstok()用法及代码示例
- C++ map key_comp()用法及代码示例
- C++ wcsncpy()用法及代码示例
- C++ imag()用法及代码示例
- C++ real()用法及代码示例
- C++ wcsstr()用法及代码示例
注:本文由纯净天空筛选整理自AmanSrivastava1大神的英文原创作品 iswpunct() function in C/C++。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。