class template
<string>

std::char_traits

template <class charT> struct char_traits;template <> struct char_traits<char>;template <> struct char_traits<wchar_t>;
template <class charT> struct char_traits;template <> struct char_traits<char>;template <> struct char_traits<wchar_t>;template <> struct char_traits<char16_t>;template <> struct char_traits<char32_t>;
Character traits
Character traits classes specify character properties and provide specific semantics for certain operations on characters and sequences of characters.

The standard library includes a standard set of character traits classes that can be instantiated from the char_traits template, and which are used by default both for the basic_string objects and for the input/output stream objects. But any other class that follows the requirements of a character traits class can be used instead. This reference attempts to describe both the definition of the standard char_traits and the requirements for custom character traits classes.

Template parameters

charT
Character type.
The class defines the standard character traits for this character type.
This shall be one of the types for which an specialization is provided.
Aliased as member type char_traits::char_type.

Template specializations

The char_traits standard template supports to be instantiated with at least the following character types:

typeDescription
charBasic character set (size of 1 byte)
wchar_tWide character set (same size, signedness, and alignment as another integral type)
charBasic character set (size of 1 byte)
wchar_tWidest character set (same size, signedness, and alignment as another integral type)
char16_tRepresents 16-bit code units (same size, signedness, and alignment as uint_least16_t)
char32_tRepresents any of the 32-bit code points (same size, signedness, and alignment as uint_least32_t)

Member types

member typedescription for character traits typesdefinition
charwchar_t
char_typeThe template parameter (charT)charwchar_t
int_typeIntegral type that can represent all charT values, as well as eof()intwint_t
off_typeA type that behaves like streamoffstreamoffstreamoff
pos_typeA type that behaves like streamposstreamposwstreampos
state_typeMultibyte transformation state type, such as mbstate_tmbstate_tmbstate_t
member typedescription for character traits typesdefinition
charwchar_tchar16_tchar32_t
char_typeThe template parameter (charT)charwchar_tchar16_tchar32_t
int_typeIntegral type that can represent all charT values, as well as eof()intwint_tuint_least16_tuint_least32_t
off_typeA type that behaves like streamoffstreamoffstreamoffstreamoffstreamoff
pos_typeA type that behaves like streamposstreamposwstreamposu16streamposu32streampos
state_typeMultibyte transformation state type, such as mbstate_tmbstate_tmbstate_tmbstate_tmbstate_t

Member functions