User's Guide

3.5 Code Conversion

The process of converting between a sequence of wide characters and a sequence of narrow characters is known as code conversion. The C++ standard library defines a locale facet std::codecvt that encapulates code conversion. The class template codecvt has three template parameters, representing an internal character type, an external character type and a type to store a code conversion state. The internal character type is so named because it is typically the type used to store wide characters in memory for processing by an application; the external character type is so named because it is typically the character type used to store charatcres in external media such as files. Most of the time, the internal character type is wchar_t, the external character type is char and the code conversion state is std::mbstate_t, an implementation-defined type specified by the C++ standard.

Streams and stream buffers do not perform code conversion by default. Of the streams and stream buffers defined in the C++ standard library, only the file-based streams perform code conversion. To write a stream or stream buffer that performs code conversion, use the class template code_converter, which performs code conversion using a std::codecvt facet.