template < class Codecvt, class Elem = wchar_t, class Tr = char_traits<Elem> > class wbuffer_convert : public std::basic_streambuf<Elem,Tr>;
Convert to/from wide buffer
Stream buffer class that handles (wide) characters of type Elem with Tr as traits.
The class uses another stream buffer of bytes (narrow characters of type
char) as its underlying byte stream buffer to/from which it converts wide characters of type Elem (its second template argument).
For the conversions, the class uses a conversion object of type Codecvt, of which it acquires ownership on construction, becoming responsible for its deletion at some point (when it is itself destroyed).
- Type of the conversion object: This shall be a class with the same properties as the codecvt locale facet, such as one of the standard classes defined in header <codecvt>.
- Wide character type.
This shall correspond to the internal type of the codecvt-like conversion object.
- Character traits class.
The object stores internally the following data elements:
|A pointer to its underlying byte stream buffer, accessed with member rdstate|
|Codecvt*||A pointer to a conversion object|
|state_type||A conversion state object, accessed with member state|
- Construct wbuffer_convert (public member function)
- Get/set underlying byte stream buffer (public member function)
- Conversion shift state (public member function)
// 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)