C++ 中的wctrans() 函数返回对应于转换的 wctrans_t 类型的值。
wctrans() 函数在<cwctype> 头文件中定义。
wctrans()原型
wctrans_t wctrans(const char* str);
wctrans() 函数将 C 字符串作为其参数并返回用于映射宽字符的 wctrans_t 类型的值。
参数:
str
:指定所需转换的 C 字符串。
返回:
- wctrans() 函数返回一个 wctrans_t 对象,该对象可与 towctrans() 一起用于映射宽字符。
- 如果
str
不提供当前 C 语言环境支持的映射,则返回零。
示例:wctrans() 函数如何工作?
#include <cwctype>
#include <iostream>
#include <cwchar>
#include <clocale>
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t str[] = L"Ŝŵitĉhiňģ Ćăse";
wcout << L"Before transformation" << endl;
wcout << str << endl;
for(int i=0; i<wcslen(str); i++)
{
if (iswctype(str[i], wctype("lower")))
str[i] = towctrans(str[i], wctrans("toupper"));
else if (iswctype(str[i], wctype("upper")))
str[i] = towctrans(str[i], wctrans("tolower"));
}
wcout << L"After transformation" << endl;
wcout << str << endl;
return 0;
}
运行程序时,输出将是:
Before transformation Ŝŵitĉhiňģ Ćăse After transformation ŝŴITĈHIŇĢ ćĂSE
相关用法
- C++ wctrans()用法及代码示例
- C++ wctob()用法及代码示例
- C++ wctomb()用法及代码示例
- C++ wctype()用法及代码示例
- C++ wcstold()用法及代码示例
- C++ wcerr用法及代码示例
- C++ wcsftime()用法及代码示例
- C++ wcstod()用法及代码示例
- C++ wcscspn()用法及代码示例
- C++ wcsncmp()用法及代码示例
- C++ wcin用法及代码示例
- C++ wcstok()用法及代码示例
- C++ wcsstr()用法及代码示例
- C++ wcsrchr()用法及代码示例
- C++ wcsncpy()用法及代码示例
- C++ wcslen()用法及代码示例
- C++ wcsspn()用法及代码示例
- C++ wclog用法及代码示例
- C++ wcschr()用法及代码示例
- C++ wcstof()用法及代码示例
注:本文由纯净天空筛选整理自 C++ wctrans()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。