public member function
<locale>
wbuffer_convert (streambuf* bytebuf = nullptr, Codecvt* pcvt = new Codecvt, state_type state = state_type());
explicit wbuffer_convert (streambuf* bytebuf = nullptr, Codecvt* pcvt = new Codecvt, state_type state = state_type()); wbuffer_convert (const wbuffer_convert&) = delete;
Construct wbuffer_convert
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.
wbuffer_convert objects cannot be copied (both the copy-constructor and copy-assignment are deleted). [C++14]
Parameters
- bytebuf
- 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>).
- pcvt
- Pointer to a conversion object (such as those of the types declared in <codecvt>) whose storage has already been allocated with
new
.
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).
- state
- 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).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
// 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):
std::filebuf myfile;
myfile.open("test.txt",std::ios::out|std::ios::binary);
// 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)
return 0;
}
|
Data races
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.
Exception safety
Strong guarantee: no effects in case an exception is thrown.