wctrans() function in C/C++
This wctrans() in C/C++ is specified in header file cwctype.h and returns a value of type wctrans_t that corresponds to the transformation. A specific locale can accept multiple transformations for characters. Some following transformation are recognized as follows :
Syntax:
wctrans_t wctrans( const char* string )
Parameters: The function accepts one mandatory parameter string which specifies a string identifying a character transformation.
Return value : The function returns two value as below:
- If current locale doesn’t provide a mapping then it returns zero.
- Otherwise, It returns object that can be used with towctrans() for mapping wide characters.
Below programs illustrate the above function:
Program 1 :
// C++ program to illustrate // towctrans() function #include <bits/stdc++.h> using namespace std; int main() { // initilize the string wchar_t string[] = L"GeeksForGeeks"; wcout << L"Initial string -> " << string << endl; wctype_t first = wctype("lower"); wctype_t second = wctype("upper"); // traverse each character and convert // lower case to upper and upper to lower for (int i = 0; i < wcslen(string); i++) { if (iswctype(string[i], first)) string[i] = towctrans(string[i], wctrans("toupper")); else if (iswctype(string[i], second)) string[i] = towctrans(string[i], wctrans("tolower")); } // print the string after transformation wcout << L"After transformation -> " << string << endl; return 0; } |
Initial string -> GeeksForGeeks After transformation -> gEEKSfORgEEKS
Program 2 :
// C++ program to illustrate // towctrans() function #include <bits/stdc++.h> using namespace std; int main() { // initilize the string wchar_t string[] = L"gfg"; wcout << L"Initial string -> " << string << endl; wctype_t first = wctype("lower"); wctype_t second = wctype("upper"); // traverse each character and convert // lower case to upper and upper to lower for (int i = 0; i < wcslen(string); i++) { if (iswctype(string[i], first)) string[i] = towctrans(string[i], wctrans("toupper")); else if (iswctype(string[i], second)) string[i] = towctrans(string[i], wctrans("tolower")); } // print the string after transformation wcout << L"After transformation -> " << string << endl; return 0; } |
Initial string -> gfg After transformation -> GFG
Recommended Posts:
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- div() function in C++
- log() function in C++
- exp() function C++
- arc function in C
- fma() function in C++
- iswdigit() function in C/C++
- iswctype() function in C/C++
- unordered_multiset end() function in C++ STL
- strtoumax() function in C++
- wctype() function in C/C++
- strtoimax() function in C++
- strtod() function in C/C++
- wcstoll() function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ManasChhabra2



