C++ <cwctype> - towctrans() Function
The C++ <cwctype> towctrans() function applies a transformation specified by desc to the wide character wc.
The setting of the LC_CTYPE category at the time of calling the function will be the same as when wctrans() was called to obtain desc. A specific locale can accept multiple transformations for characters. At least the following transformations supported in all C locales are as follows:
string passed to wctrans() function | Effect |
---|---|
"tolower" | Identifies the transformations used by towlower() |
"toupper" | Identifies the transformations used by towupper() |
Syntax
wint_t towctrans( wint_t wc, wctrans_t desc );
Parameters
wc |
Specify the wide character to be transformed, casted to a wint_t value, or WEOF. |
desc |
Specify a LC_CTYPE transformation, obtained from a call to wctrans(). |
Return Value
Returns the transformed value of wc using the transformation identified by desc if such value exists, or wc (unchanged) otherwise.
Example:
The example below shows the usage of towctrans() function.
#include <cstdio> #include <cwchar> #include <cwctype> int main (){ int i = 0; wchar_t str[50] = L"99HEllo@"; wchar_t c; //displaying the alphabetic //character in lower case wctype_t check = wctype("alpha"); wctrans_t trans = wctrans("tolower"); while (str[i]) { c = str[i]; if (iswctype(c, check)) { c = towctrans(c, trans); putwchar (c); } i++; } return 0; }
The output of the above code will be:
hello
❮ C++ <cwctype> Library