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++。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。