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


iswdigit() 函式是 C/C++ 中的內建函式。它檢查寬字元是否是十進位制數字。它在 C++ 語言中宣告在“cwctype”標頭檔案中,而在 C 語言中宣告在“ctype.h”標頭檔案中。它接收一個稱為寬字元的單個字元。

0 到 9 之間的字元被歸類為十進位制數字。如果寬字元不是十進位制數字,它將返回零 (0)。如果字元是數字,它將返回非零值。

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

int iswdigit(ch)

以下是在 C++ 語言中 iswdigit() 的一個示例:

示例

 線上演示

#include <cwctype>
#include <iostream>
using namespace std;
int main() {
   wchar_t c1 = '!';
   wchar_t c2 = '8';
   if (iswdigit(c1))
   wcout << c1 << " , The character is a digit ";
   else
   wcout << c1 << " , The character is not a digit ";
   wcout << endl;
   if (iswdigit(c2))
   wcout << c2 << ", The character is a digit ";
   else
   wcout << c2 << ", The character is not a digit ";
   return 0;
}

輸出

! , The character is not a digit
8 , The character is a digit

更新時間:2020-06-24

175 次瀏覽

啟動你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.