std:: towctrans
From cppreference.net
C++
Text processing library
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
Null-terminated wide strings
| Functions | ||||||||||||||||||||||||||
| Character classification | ||||||||||||||||||||||||||
| Character manipulation | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| Conversions to numeric formats | ||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||
| String manipulation | ||||||||||||||||||||||||||
| String examination | ||||||||||||||||||||||||||
| Array manipulation | ||||||||||||||||||||||||||
|
定义于头文件
<cwctype>
|
||
|
std::
wint_t
towctrans
(
std::
wint_t
ch,
std::
wctrans_t
desc
)
;
|
||
将宽字符 ch 通过由 desc 指定的当前C本地化环境的 LC_CTYPE 映射类别进行转换。
如果 ch 的值既不能表示为 wchar_t ,也不等于宏 WEOF 的值,则行为是未定义的。
目录 |
参数
| ch | - | 待映射的宽字符 |
| desc | - | 通过调用 LC_CTYPE 映射描述符,从 std::wctrans 获取 |
返回值
使用当前 C 本地环境的 LC_CTYPE 分面中由 desc 标识的映射规则,对 ch 进行映射后的值。
示例
以下示例演示片假名到平假名的字符映射。
运行此代码
#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 << "katakana characters " << kana << " are " << tohira(kana) << " in hiragana\n"; }
输出:
katakana characters ヒラガナ are ひらがな in hiragana
参见
|
在当前C本地环境中查找字符映射类别
(函数) |
|
|
C 文档
for
towctrans
|
|