名稱空間
變體
操作

std::wstring_convert

來自 cppreference.com
< cpp‎ | locale
 
 
 
 
 
定義於標頭檔案 <locale>
template<

    class Codecvt,
    class Elem = wchar_t,
    class Wide_alloc = std::allocator<Elem>,
    class Byte_alloc = std::allocator<char>

> class wstring_convert;
(C++11 起)
(C++17 中已棄用)
(C++26 中移除)

類模板 std::wstring_convert 使用獨立的字元轉換平面 Codecvt 在位元組字串 std::string 和寬字串 std::basic_string<Elem> 之間執行轉換。std::wstring_convert 擁有該轉換平面的所有權,並且不能使用由 locale 管理的平面。

適用於 std::wstring_convert 的標準平面是用於 UTF-8/UCS-2 和 UTF-8/UCS-4 轉換的 std::codecvt_utf8 和用於 UTF-8/UTF-16 轉換的 std::codecvt_utf8_utf16

目錄

[編輯] 巢狀型別

型別 定義
byte_string std::basic_string<char, std::char_traits<char>, Byte_alloc>
wide_string std::basic_string<Elem, std::char_traits<Elem>, Wide_alloc>
state_type typename Codecvt::state_type
int_type typename wide_string::traits_type::int_type

[編輯] 資料成員

成員 描述
byte_string byte_err_string 出錯時顯示的位元組字串
(僅用於闡釋的成員物件*)
wide_string wide_err_string 出錯時顯示的寬字串
(僅用於闡釋的成員物件*)
Codecvt* cvtptr 指向已分配轉換物件的指標
(僅用於闡釋的成員物件*)
state_type cvtstate 轉換狀態物件
(僅用於闡釋的成員物件*)
std::size_t cvtcount 轉換計數
(僅用於闡釋的成員物件*)

[編輯] 成員函式

構造新的 wstring_convert
(public member function) [編輯]
operator=
複製賦值運算子已被刪除
(公開成員函式)
銷燬 wstring_convert 及其轉換平面
(public member function) [編輯]
將位元組字串轉換為寬字串
(public member function) [編輯]
將寬字串轉換為位元組字串
(public member function) [編輯]
返回成功轉換的字元數
(public member function) [編輯]
返回當前轉換狀態
(public member function) [編輯]

[編輯] 參閱

字元
轉換
由區域設定定義的多位元組
(UTF-8, GB18030)
UTF-8
UTF-16
UTF-16 mbrtoc16 / c16rtomb (帶 C11 的 DR488)

codecvt<char16_t,char,mbstate_t>
codecvt_utf8_utf16<char16_t>
codecvt_utf8_utf16<char32_t>
codecvt_utf8_utf16<wchar_t>

不適用
UCS-2 c16rtomb (不帶 C11 的 DR488) codecvt_utf8<char16_t> codecvt_utf16<char16_t>
UTF-32

mbrtoc32 / c32rtomb

codecvt<char32_t,char,mbstate_t>
codecvt_utf8<char32_t>

codecvt_utf16<char32_t>

系統 wchar_t

UTF-32 (非 Windows)
UCS-2 (Windows)

mbsrtowcs / wcsrtombs
use_facet<codecvt
<wchar_t,char,mbstate_t>>(locale)

codecvt_utf8<wchar_t> codecvt_utf16<wchar_t>
(C++11)(C++17 中已棄用)(C++26 中已移除)
執行位元組流緩衝區和寬流緩衝區之間的轉換
(類模板) [編輯]
(C++11)(C++17 中已棄用)(C++26 中已移除)
在 UTF-8 和 UCS-2/UCS-4 之間轉換
(類模板) [編輯]
(C++11)(C++17 中已棄用)(C++26 中已移除)
在 UTF-8 和 UTF-16 之間轉換
(類模板) [編輯]