名前空間
変種
操作

std::wstring_convert<Codecvt,Elem,Wide_alloc,Byte_alloc>::converted

From cppreference.com
 
 
 
 
 
ヘッダー <locale> で定義
std::size_t converted() const noexcept;

直近のfrom_bytes() または to_bytes() によって正常に処理されたソース文字数を返します。

目次

[編集] 戻り値

cvtcount

[編集]

#include <codecvt>
#include <iostream>
#include <locale>
#include <string>
 
int main()
{
    std::string utf8 = "z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋"
                   // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";
    std::cout << "original UTF-8 string size: " << utf8.size() << '\n';
 
    // the UTF-8 - UTF-32 standard conversion facet
    std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> cvt;
 
    // UTF-8 to UTF-32
    std::u32string utf32 = cvt.from_bytes(utf8);
    std::cout << "UTF-32 string size: " << utf32.size() << '\n';
    std::cout << "converted() == " << cvt.converted() << '\n';
 
    // UTF-32 to UTF-8
    utf8 = cvt.to_bytes(utf32);
    std::cout << "new UTF-8 string size: " << utf8.size() << '\n';
    std::cout << "converted() == " << cvt.converted() << '\n';
}

出力

original UTF-8 string size: 10
UTF-32 string size: 4
converted() == 10
new UTF-8 string size: 10
converted() == 4

[編集] 不具合報告

以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。

DR 適用対象 公開された動作 正しい動作
LWG 2174 C++11 wstring_convert::converted は noexcept である必要はありませんでした。 必要

[編集] 関連項目

ワイド文字列をバイト文字列に変換する
(public メンバ関数) [編集]
バイト文字列をワイド文字列に変換する
(public メンバ関数) [編集]
English 日本語 中文(简体) 中文(繁體)