C++ STL 中的 iswspace() 函式


本文將探討 C++ 中的 iswspace() 函式,包括其語法、功能和返回值。

iswspace() 函式是 C++ 中的一個內建函式,定義在標頭檔案中。該函式檢查所傳遞的寬字元是否為空格字元。該函式是 isspace() 的寬字元等價項,這意味著它的功能與 isspace() 相同,不同之處在於它支援寬字元。該函式檢查傳遞的引數是否為空格(‘ ’),如果是則返回非零整數值(true),否則返回 0(false)。

語法

int iswspace(wint_t ch);

該函式只接受一個引數,即要檢查的寬字元。該引數被強制轉換為 wint_t 或 WEOF。

wint_t 儲存整型資料。

返回值

該函式返回一個整數值,它可以是 0(false)或任何非零值(true)。

示例

 線上演示

#include <iostream>
#include <cwctype>
using namespace std;
int main() {
   wint_t a = '.';
   wint_t b = ' ';
   wint_t c = '1';
   iswspace(a)?cout<<"\nIts white space character":cout<<"\nNot white space character";
   iswspace(b)?cout<<"\nIts white space character":cout<<"\nNot white space character";
   iswspace(c)?cout<<"\nIts white space character":cout<<"\nNot white space character";
}

輸出

如果執行以上程式碼,將生成以下輸出:

Not white space character
Its white space character
Not white space character

示例

 線上演示

#include <iostream>
#include <cwctype>
using namespace std;
int main () {
   int i, count;
   wchar_t s[] = L"I am visiting tutorials point";
   count = i = 0;
   while (s[i]) {
      if(iswspace(s[i]))
         count++;
      i++;
   }
   cout<<"There are "<<count <<" white space characters.\n";
   return 0;
}

輸出

如果執行以上程式碼,將生成以下輸出:

There are 4 white space characters.

更新於:2020 年 2 月 28 日

114 檢視次

開啟你的 職業生涯

完成課程以獲得認證

開始
廣告
© . All rights reserved.