C/C++ 中的 iswblank() 函式


iswblank() 函式用於檢查傳遞的寬字元是否為空。它基本上是空格字元,同時它還考慮製表符 (\t)。此函式在 C 語言中宣告在 “ctype.h” 標頭檔案中,在 C++ 語言中宣告在 “cctype”” 標頭檔案中。

以下是在 C++ 語言中 isblank() 的語法:

int iswblank(wint_t char);

以下是 C++ 語言中 iswblank() 的示例:

示例

 動態演示

#include <ctype.h>
#include <iostream>
using namespace std;
int main() {
   wchar_t s[] = L"The space between words.";
   int i = 0;
   int count = 0;
   while(s[i]) {
      char c = s[i++];
      if (iswblank(c)) {
         count++;
      }
   }
   cout << "\nNumber of blanks in sentence : " << count << endl;
   return 0;
}

輸出

Number of blanks in sentence : 5

在上述程式中,字串傳遞在變數 s 中。函式 iswblank() 用於檢查傳遞的字串中的空格或空白,如下面的程式碼片段所示。

wchar_t s[] = L"The space between words.";
int i = 0;
int count = 0;
while(s[i]) {
   char c = s[i++];
   if (iswblank(c)) {
      count++;
   }
}

更新日期:2020-06-26

151 次瀏覽

開啟你的 職業

透過完成課程獲得證書

開始
廣告
© . All rights reserved.