这 wctrans() 在C/C++中,在头文件中指定 cwctype。H 并返回与转换对应的wctrans_t类型的值。特定区域设置可以接受字符的多个转换。以下一些转换被认为是:
null
语法:
wctrans_t wctrans( const char* string )
参数: 该函数接受一个强制参数 一串 它指定标识字符转换的字符串。 返回值: 该函数返回两个值,如下所示:
- 如果当前语言环境不提供映射,则返回零。
- 否则,它将返回可与towctrans()一起用于映射宽字符的对象。
以下程序说明了上述功能: 项目1:
CPP
// C++ program to illustrate // towctrans() function #include <bits/stdc++.h> using namespace std; int main() { // initialize 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 -> GeeksForGeeksAfter transformation -> gEEKSfORgEEKS
项目2:
CPP
// C++ program to illustrate // towctrans() function #include <bits/stdc++.h> using namespace std; int main() { // initialize 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 -> gfgAfter transformation -> GFG
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END