C++ Standard Library C++ STL Library

C++ <cwctype> - wctrans() Function



The C++ <cwctype> wctrans() function returns a value of type wctrans_t that corresponds to the character transformation specified by property.

The value returned by this function depends on the LC_CTYPE category selected. A specific locale can accept multiple transformations in which to classify its characters.

Syntax

wctrans_t wctrans (const char* property);           

Parameters

property

Specify a C string holding the name of the desired transformations. The values of property supported in all C locales are as follows:

Value of propertyEffect
"tolower" Identifies the transformations used by towlower()
"toupper" Identifies the transformations used by towupper()

Return Value

Returns a value of type wctrans_t identifying a specific character category. This value is locale-dependent. Returns zero if property does not name a mapping supported by the current C locale.

Example:

The example below shows the usage of wctrans() 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 upper case
  wctype_t check = wctype("alpha");
  wctrans_t trans = wctrans("toupper");
  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