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.

更新於: 28-Feb-2020

75 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.