Namespaces
Variants
Views
Actions

std::towctrans

From cppreference.com
< cpp‎ | string‎ | wide
Revision as of 14:22, 2 November 2012 by P12bot (Talk | contribs)

Defined in header <cwctype>
std::wint_t towctrans( std::wint_t wc, std::wctrans_t desc );

Maps the wide character wc using the current C locale's LC_CTYPE mapping category identified by desc.

Contents

Parameters

ch - the wide character to map
desc - the LC_CTYPE mapping, obtained from a call to std::wctrans

Return value

The mapped value of ch using the mapping identified by desc in LC_CTYPE facet of the current C locale.

Example

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";
}

Output:

katakana characters ヒラガナ are ひらがな in hiragana

See also

Template:cpp/string/wide/dcl list wctrans
C documentation for towctrans