名前空間
変種
操作

std::btowc

From cppreference.com
< cpp‎ | string‎ | multibyte
 
 
 
 
ヘッダ <cwchar> で定義
std::wint_t btowc( int c );

1バイト文字 c をそのワイド文字相当に変換します。

ほとんどのマルチバイト文字エンコーディングでは、ASCII 文字セットからの文字を表現するために 1 バイトコードを使用します。この関数は、そのような文字を wchar_t に変換するために使用できます。

目次

[編集] パラメータ

c - 変換する 1 バイト文字

[編集] 戻り値

WEOFcEOF の場合。

ワイド文字: (unsigned char)c が初期シフト状態において有効な 1 バイト文字である場合、そのワイド文字表現。それ以外の場合は WEOF

[編集]

#include <clocale>
#include <cwchar>
#include <iostream>
 
void try_widen(char c)
{
    std::wint_t w = std::btowc(c);
    if (w != WEOF)
        std::cout << "The single-byte character " << +(unsigned char)c
                  << " widens to " << +w << '\n';
    else
        std::cout << "The single-byte character " << +(unsigned char)c
                  << " failed to widen\n";
}
 
int main()
{
    std::setlocale(LC_ALL, "lt_LT.iso88594");
    std::cout << std::hex << std::showbase << "In Lithuanian ISO-8859-4 locale:\n";
    try_widen('A');
    try_widen('\xdf'); // German letter ß (U+00df) in ISO-8859-4
    try_widen('\xf9'); // Lithuanian letter ų (U+0173) in ISO-8859-4
 
    std::setlocale(LC_ALL, "lt_LT.utf8");
    std::cout << "In Lithuanian UTF-8 locale:\n";
    try_widen('A');
    try_widen('\xdf');
    try_widen('\xf9');
}

実行結果の例

In Lithuanian ISO-8859-4 locale:
The single-byte character 0x41 widens to 0x41
The single-byte character 0xdf widens to 0xdf
The single-byte character 0xf9 widens to 0x173
In Lithuanian UTF-8 locale:
The single-byte character 0x41 widens to 0x41
The single-byte character 0xdf failed to widen
The single-byte character 0xf9 failed to widen

[編集] 関連情報

可能であれば、ワイド文字を1バイトのナロー文字にナロー化する
(関数) [編集]
[virtual]
charからCharTへ文字または文字を変換します。
(virtual protected member function of std::ctype<CharT>) [編集]
English 日本語 中文(简体) 中文(繁體)