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

std::wbuffer_convert::wbuffer_convert

explicit wbuffer_convert( std::streambuf* bytebuf = 0, Codecvt* pcvt = new Codecvt, state_type state = state_type() );

(1)

?

wbuffer_convert(const std::wbuffer_convert&) = delete;

(2)

(since C++14)

1%29构造wbuffer_convert对象具有指定的基础字节流(指定)。codecvt方面和指定的初始转换状态%28所有参数都是可选的%29。

2%29复制构造函数被删除,wbuffer_convert不是CopyConstructible

参数

bytebuf

-

pointer to std::streambuf to serve as the underlying narrow character stream

pcvt

-

pointer to a standalone (not managed by a locale) std::codecvt facet. The behavior is undefined if this pointer is null.

state

-

the initial value of the character conversion state

二次

代码语言:javascript
复制
#include <iostream>
#include <sstream>
#include <locale>
#include <codecvt>
int main()
{
    // wrap a UTF-8 string stream in a UCS4 wbuffer_convert
    std::stringbuf utf8buf(u8"z\u00df\u6c34\U0001f34c");  // or u8"z?水?"
                       // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9f\x8d\x8c";
    std::wbuffer_convert<std::codecvt_utf8<wchar_t>> conv_in(&utf8buf);
    std::wistream ucsbuf(&conv_in);
    std::cout << "Reading from a UTF-8 stringbuf via wbuffer_convert:\n";
    for(wchar_t c; ucsbuf.get(c); )
        std::cout << std::hex << std::showbase << c << '\n';
 
    // wrap a UTF-8 aware std::cout in a UCS4 wbuffer_convert to output UCS4
    std::wbuffer_convert<std::codecvt_utf8<wchar_t>> conv_out(std::cout.rdbuf());
    std::wostream out(&conv_out);
    std::cout << "Sending UCS4 data to std::cout via wbuffer_convert:\n";
    out << L"z\u00df\u6c34\U0001f34c\n";
}

二次

产出:

二次

代码语言:javascript
复制
Reading from a UTF-8 stringbuf via wbuffer_convert produces
0x7a
0xdf
0x6c34
0x1f34c
Sending UCS4 data to std::cout via wbuffer_convert:
z?水?

二次

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com