std::wstring_convert<Codecvt,Elem,Wide_alloc,Byte_alloc>::from_bytes
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <locale> で定義
|
||
wide_string from_bytes( char byte ); |
(1) | |
wide_string from_bytes( const char* ptr ); |
(2) | |
wide_string from_bytes( const byte_string& str ); |
(3) | |
wide_string from_bytes( const char* first, const char* last); |
(4) | |
構築時に供給された codecvt ファセットを用いて、マルチバイトからワイドへの変換を行います。
1) 長さ
1 の文字列であるかのように、 byte を wide_string に変換します。2)
ptr の指す文字から始まるヌル終端マルチバイト文字シーケンスを wide_string に変換します。3) ナロー文字列
str を wide_string に変換します。4) ナローマルチバイト文字シーケンス
[first, last) を wide_string に変換します。すべての場合において、非初期開始状態がこの wstring_convert のコンストラクタに提供された場合を除き、変換は初期シフト状態で開始します。 変換された文字数および変換状態の最終値は記憶され、 state() および converted() でアクセスすることができます。
戻り値
マルチバイトからワイドへの変換の結果を格納する wide_string オブジェクト。 変換が失敗し、この wstring_convert のコンストラクタに提供されたユーザ供給のワイドエラー文字列があった場合は、そのワイドエラー文字列を返します。
例外
この wstring_convert オブジェクトがユーザ提供のワイドエラー文字列なしに構築された場合は、変換失敗時に std::range_error を投げます。
例
Run this code
#include <iostream>
#include <string>
#include <locale>
#include <codecvt>
int main()
{
std::string utf8 = u8"z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋"
// or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";
// the UTF-8 / UTF-16 standard conversion facet
std::u16string utf16 = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(utf8.data());
std::cout << "UTF16 conversion produced " << utf16.size() << " code units:\n";
for (char16_t c : utf16)
std::cout << std::hex << std::showbase << c << '\n';
// the UTF-8 / UTF-32 standard conversion facet
std::u32string utf32 = std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t>{}.from_bytes(utf8);
std::cout << "UTF32 conversion produced " << std::dec << utf32.size() << " code units:\n";
for (char32_t c : utf32)
std::cout << std::hex << std::showbase << c << '\n';
}
出力:
UTF16 conversion produced 5 code units:
0x7a
0xdf
0x6c34
0xd834
0xdd0b
UTF32 conversion produced 4 code units:
0x7a
0xdf
0x6c34
0x1d10b
関連項目
| ワイド文字列をバイト文字列に変換します (パブリックメンバ関数) | |
| 指定された状態を使用してマルチバイト文字列をワイド文字列に変換します (関数) | |
[仮想] |
ファイルから読み込む時などのために、文字列を externT から internT に変換します ( std::codecvt<InternT,ExternT,State>の仮想プロテクテッドメンバ関数)
|