名稱空間
變體
操作

std::towctrans

來自 cppreference.com
< cpp‎ | string‎ | wide
定義於標頭檔案 <cwctype>
std::wint_t towctrans( std::wint_t ch, std::wctrans_t desc );

使用當前 C 語言環境的 LC_CTYPE 對映類別(由 desc 標識)對映寬字元 ch

如果 ch 的值既不能表示為 wchar_t,也不等於宏 WEOF 的值,則行為未定義。

目錄

[編輯] 引數

ch - 要對映的寬字元
desc - 從呼叫 std::wctrans 獲得的 LC_CTYPE 對映

[編輯] 返回值

使用當前 C 語言環境的 LC_CTYPE facet 中由 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 語言環境中查詢字元對映類別
(function) [編輯]
C 文件 中關於 towctrans 的內容