X Tutup
The Wayback Machine - https://web.archive.org/web/20171016154034/http://zh.cppreference.com:80/w/cpp/string/wide/towctrans

std::towctrans

来自cppreference.com
< cpp‎ | string‎ | wide

定义于头文件 <cwctype>
std::wint_t towctrans( std::wint_t wc, std::wctrans_t desc );
。地图的宽字符wc使用当前的C语言环境的LC_CTYPE确定的映射类的desc.
原文:
Maps the wide character wc using the current C locale's LC_CTYPE mapping category identified by desc.
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

[编辑] 。参数。

ch -
。的宽字符映射。
原文:
the wide character to map
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。
desc -
。的LC_CTYPE映射,从调用std::wctrans获得。
原文:
the LC_CTYPE mapping, obtained from a call to std::wctrans
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

===。 返回值。===

ch使用映射desc在LC_CTYPE方面目前的C语言环境确定的映射值的.
原文:
The mapped value of ch using the mapping identified by desc in LC_CTYPE facet of the current C locale.
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

[编辑] 。为例。

。下面的例子演示片假名到平假名映射。
原文:
The following example demonstrates katakana to hiragana character mapping
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

#include <clocale>
#include <cwctype>
#include <iostream>
#include <algorithm>
 
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 本地环境中查找字符映射类别
(函数) [编辑]
towctransC 文档
X Tutup