wctype() function in C/C++
Last Updated :
04 Sep, 2018
The
wctype() is a built-in function in C/C++ which returns a value of type wctype_t that is used for classifying a wide character. It is defined within the
cwctype header file of C++. The following are the possible type wctype_t:
Value of str |
Equivalent function |
space |
iswspace |
upper |
iswupper |
xdigit |
iswxdigit |
print |
iswprint |
punct |
iswpunct |
graph |
iswgraph |
lower |
iswlower |
cntrl |
iswcntrl |
digit |
iswdigit |
alpha |
iswalpha |
blank |
iswblank |
alnum |
iswalnum |
Syntax:
wctype_t wctype(const char* str)
Parameter: The function accepts a single mandatory parameter
str which specifies the desired wctype category.
Return Value: The function returns two values as shown below:
- The function returns a wctype_t object that can be used with iswctype() ortowctype() to check a wide character's property.
- If str doesn't provide a category supported by the current C locale, it returns zero.
Below programs illustrates the above function.
Program 1:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t wc = L'@';
// checks if the type is digit
if (iswctype(wc, wctype("digit")))
wcout << wc << L" is a digit";
// checks if the type is alpha
else if (iswctype(wc, wctype("alpha")))
wcout << wc << L" is an alphabet";
else
wcout << wc << L" is neither an"
<< " alphabet nor a digit";
return 0;
}
Output:
@ is neither an alphabet nor a digit
Output:
@ is neither an alphabet nor a digit
Program 2:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t wc = L'g';
// checks if the type is digit
if (iswctype(wc, wctype("digit")))
wcout << wc << L" is a digit";
// checks if the type is alpha
else if (iswctype(wc, wctype("alpha")))
wcout << wc << L" is an alphabet";
else
wcout << wc << L" is neither"
<< " an alphabet nor a digit";
return 0;
}
Explore
C++ Basics
Core Concepts
OOP in C++
Standard Template Library(STL)
Practice & Problems