首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::wstring_convert::converted

Defined in header <locale>

std::size_t converted() const;

返回最近处理的源字符数。from_bytes()to_bytes()...

返回值

最近一次转换操作所消耗的字符数。

例外

(none)

(until C++14)

noexcept specification: noexcept

(since C++14)

二次

代码语言:javascript
复制
#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";
    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';
}

二次

产出:

二次

代码语言:javascript
复制
original UTF-8 string size: 10
UTF-32 string size: 4
converted() == 10
new UTF-8 string size: 10
converted() == 4

二次

另见

to_bytes

converts a wide string into a byte string (public member function)

from_bytes

converts a byte string into a wide string (public member function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券