std::wbuffe...nvert::rdbuf(3)
π NAME π
std::wbuffer_convert::rdbuf β std::wbuffer_convert::rdbuf, bestie. Yes, the NAME section said it twice, and honestly? Iconic. This is from the C++ Standard Libary manual, section 3 β the header/page label is std::wbuffe...nvert::rdbuf(3), because terminal widths are lowkey haters ππ
.
β¨ Synopsis β¨
Defined in header <locale>, bestie:
std::streambuf* rdbuf() const; (1)
std::streambuf* rdbuf( std::streambuf* bytebuf ); (2)
- Returns the pointer to the underlying byte stream.
- Replaces the associated byte stream with
bytebuf.
π Return value π
- The current underlying byte stream.
- The previous byte stream.
πΈ Example πΈ
Okay so run this code, fr fr:
// Run this code
#include <codecvt>
#include <iostream>
#include <locale>
#include <sstream>
int main()
{
// Convert UTF-8 to UCS4
std::stringbuf utf8buf("z\u00df\u6c34\U0001d10b");
// or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b"
// or u8"zΓζ°΄π"
std::wbuffer_convert<std::codecvt_utf8<wchar_t>> conv(&utf8buf);
std::wistream ucsbuf(&conv);
std::cout << "Reading from a UTF-8 stringbuf via wbuffer_convert: "
<< std::hex << std::showbase;
for (wchar_t c; ucsbuf.get(c);)
std::cout << static_cast<std::wint_t>(c) << ' ';
// Reuse the same wbuffer_convert to handle UCS4 to UTF-8 output
conv.rdbuf(std::cout.rdbuf());
std::wostream out(&conv);
std::cout << "\nSending UCS4 data to std::cout via wbuffer_convert:
";
out << L"z\u00df\u6c34\U0001d10b\n";
}
Output:
Reading from a UTF-8 stringbuf via wbuffer_convert: 0x7a 0xdf 0x6c34
0x1d10b
Sending UCS4 data to std::cout via wbuffer_convert: zΓζ°΄π
π¦ See also π¦
- constructor β constructs a new
wbuffer_convert(public member function)
source/version/date check, bestie: http://cppreference.com, 2024.06.10, std::wbuffe...nvert::rdbuf(3). Byeee, go slay those encoding conversions π
π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms