class template
<locale>

std::wbuffer_convert

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).

Template parameters

Codecvt
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>.
Elem
Wide character type.
This shall correspond to the internal type of the codecvt-like conversion object.
Tr
Character traits class.
Defaults to: char_traits<Elem>

Object state

The object stores internally the following data elements:
typedescription
streambuf*A pointer to its underlying byte stream buffer, accessed with member rdstate
Codecvt*A pointer to a conversion object
state_typeA conversion state object, accessed with member state

Member types

member typedefinition
state_typeCodecvt::state_type

Member functions


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);

  // 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;
}