std::towctrans
来自cppreference.com
<tbody>
</tbody>
| 在标头 <cwctype> 定义
|
||
std::wint_t towctrans( std::wint_t ch, std::wctrans_t desc ); |
||
用 desc 所标识的当前 C 本地环境的 LC_TYPE 映射宽字符 ch。
若 ch 的值既不能表示为 wchar_t 又不等于宏 WEOF,则行为未定义。
参数
| ch | - | 要映射的宽字符 |
| desc | - | 从调用 std::wctrans 获得的 LC_CTYPE 映射 |
返回值
ch 的被映射值,使用 desc 在当前 C 本地环境的 LC_TYPE 中标识的映射。
示例
下列代码演示片假名到平假名的字符映射
运行此代码
#include <algorithm>
#include <clocale>
#include <cwctype>
#include <iostream>
std::wstring tohira(std::wstring str)
{
std::transform(str.begin(), str.end(), str.begin(), [](wchar_t c)
{
return std::towctrans(c, std::wctrans("tojhira"));
});
return str;
}
int main()
{
std::setlocale(LC_ALL, "ja_JP.UTF-8");
std::wstring kana = L"ヒラガナ";
std::wcout << "片假名字符 " << kana
<< " 在平假名中是 " << tohira(kana) << "\n";
}
输出:
片假名字符 ヒラガナ 在平假名中是 ひらがな
参阅
| 在当前 C 本地环境中查找字符映射类别 (函数) | |
towctrans 的 C 文档
| |