public member function
wbuffer_convert (streambuf* bytebuf = nullptr,
Codecvt* pcvt = new Codecvt,
state_type state = state_type());
Constructs a wbuffer_convert object with its internal state initialized to the arguments passed.
The object wraps a bytebuf object, which becomes its underlying byte stream buffer
- Pointer to the underlying byte stream buffer.
streambuf is a standard instantiation of template basic_streambuf for elements of type
char (defined in header <streambuf>).
- Pointer to a conversion object (such as those of the types declared in <codecvt>) whose storage has already been allocated with
The constructed object acquires ownership of this conversion object, which is automatically destroyed (with
operator delete) when this object is destroyed. Note that this makes facets managed by locale objects not suitable to be used by wbuffer_convert.
If a null pointer is passed, it causes undefined behavior.
Codecvt is the first template parameter of wbuffer_convert (its conversion object's type).
- Initial conversion shift state. The state is carried onto the next conversion operation.
state_type is a member type, defined as an alias of Codecvt::state_type (where Codecvt is the first template parameter of wbuffer_convert).
// wbuffer_convert example
#include <iostream> // std::cout, std::ios, std::wostream
#include <locale> // std::wbuffer_convert
#include <codecvt> // std::codecvt_utf8
#include <fstream> // std::filebuf
int main ()
// file buffer (narrow buffer):
// conversor (wide buffer -> narrow buffer, using UTF-8):
std::wbuffer_convert<std::codecvt_utf8<wchar_t>> bufconv (&myfile);
// stream (wide buffer):
std::wostream mystream (&bufconv);
mystream << L"Test"; // writes wide string to file (UTF-8)
bytebuf and pcvt may be accessed/modified by future operations on the object.
Management of the storage for the element pointed by pcvt (if any) is acquired by the constructed object.
Strong guarantee: no effects in case an exception is thrown.