C++ iswctype()

The iswctype() function in C++ checks if a given wide character has a certain property.

The iswctype() function is defined in <cwctype> header file.

iswctype() prototype

int iswctype(wint_t wc, wctype_t desc);

The iswctype() function classifies the wide character wc according to the property specified by desc.

The behavior of this function might be affected by the LC_CTYPE category of the current locale.

iswctype() Parameters

  • wc: The wide character to check.
  • desc: The property to test for which is obtained from a call to wctype().

iswctype() Return value

  • The iswctype() function returns non zero value if wc has the property specified by desc, otherwise returns zero.

Example: How iswctype() function works?

#include <cwctype>
#include <iostream>
#include <clocale>
using namespace std;

int main()
	setlocale(LC_ALL, "en_US.UTF-8");
	wchar_t wc = L'\u0178';

	if (iswctype(wc, wctype("digit")))
		wcout << wc << L" is a digit";
	else if (iswctype(wc, wctype("alpha")))
		wcout << wc << L" is an alphabet";
		wcout << wc << L" is neither an alphabet nor a digit";
	return 0;

When you run the program, the output will be:

Ÿ is an alphabet