C++ Standard Library C++ STL Library

C++ <cwctype> - iswxdigit() Function



The C++ <cwctype> iswxdigit() function is used to check if the given wide character is a hexadecimal digit or not. Hexadecimal digits are one of the following character: 0123456789abcdefABCDEF.

Syntax

int iswxdigit ( wint_t ch );               

Parameters

ch Specify the wide character to be checked, casted to an wint_t, or WEOF.

Return Value

Returns non-zero value (i.e, true) if ch is a hexadecimal digit, else returns zero (i.e, false).

Example:

The example below shows the usage of iswxdigit() function.

#include <iostream>
#include <cwchar>
#include <cwctype>
using namespace std;
 
int main (){
  wchar_t str[] = L"ff123YZ";

  //counting the numbers of wide 
  //hexadecimal digits in str
  int i = 0, count = 0;
  while(str[i]) {
    if(iswxdigit(str[i]))
      count++;
    i++;
  }

  //displaying the output
  wcout<<str<<" contains "<<count<<
       " hexadecimal digits.";  
  return 0;
}

The output of the above code will be:

ff123YZ contains 5 hexadecimal digits.

❮ C++ <cwctype> Library