Name

char_traits<char> class — Character traits of char type

Synopsis

template<> struct char_traits<char> {
  typedef char char_type;
  typedef int int_type;
  typedef streamoff off_type;
  typedef streampos pos_type;
  typedef mbstate_t state_type;
   
  static void assign(char_type& dst, const char_type& src);
  static char_type* assign(char_type* dst, size_t n, const char_type& c);
  static bool eq(const char_type& c1, const char_type& c2);
  static bool lt(const char_type& c1, const char_type& c2);
  static size_t length(const char_type* str);
  static int compare(const char_type* s1, const char_type* s2, size_t n);
  static const char_type* find(const char_type* str, size_t n, 
                               const char_type& c);
  static char_type* copy(char_type* dst, char_type* src, size_t n);
  static char_type* move(char_type* dst, char_type* src, size_t n);
  static bool eq_int_type(const int_type& i1, const int_type& i2);
  static int_type eof(  );
  static int_type not_eof(const int_type& i);
  static char_type to_char_type(const int_type& i);
  static int_type to_int_type(const char_type& c);
};
See Also

The char_traits<char> class specializes char_traits for narrow characters. The streamoff type is implementation-defined. The streampos type is defined as fpos<mbstate_t> in <iosfwd>. The character traits are defined for the type char and have the same meaning in all locales. The other types are self-explanatory. The following are the member functions:

static void assign (char_type& dst, const char_type& src)

Assigns dst = src.

static char_type* assign (char_type* dst, size_t n, const char_type& c)

Fills dst with n copies of c, that is, dst[0] through dst[n-1] = c.

static int compare (const char_type* s1, const char_type* s2, size_t n)

Compares the first n characters of the arrays s1 and s2, returning an integer result:

static char_type* copy (char_type* dst, char_type* src, size_t n)

Copies n characters from src to dst. The arrays src and dst must not overlap.

static int_type eof ( )

Returns the end-of-file marker, EOF (in <cstdio>). The end-of-file marker is different from all characters, that is, for all character values c, eq_int_type(eof( ), to_int_type( c )) is false.

static bool eq (const char_type& c1, const char_type& c2)

Returns c1 == c2.

static bool eq_int_type (const int_type& i1, const int_type& i2)

Returns true if i1 is the same as i2. Specifically, for all character values c1 and c2, eq( c1, c2 ) has the same value as eq_int_type(to_int_type( c1 ), to_int_type( c2 )). Also, eof( ) is always equal to eof( ) and not equal to to_int_type( c ) for any character c. The value is unspecified for any other integer values.

static const char_type* find (const char_type* str, size_t n, const char_type& c)

Returns a pointer p to the first character in str such that eq(* p, c) is true. It returns a null pointer if there is no such character in the first n characters of str.

static size_t length (const char_type* str)

Returns the length of the null-terminated character string str, that is, it returns the smallest i such that eq(str[ i ], charT( )) is true.

static bool lt (const char_type& c1, const char_type& c2)

Returns c1 < c2.

static char_type* move (char_type* dst, char_type* src, size_t n)

Copies n characters from src to dst. The arrays src and dst are allowed to overlap.

static int_type not_eof (const int_type& i)

Returns a value that is guaranteed to be different from eof( ). If i is not eof( ), i is returned. Otherwise, some other value is returned.

static char_type to_char_type (const int_type& i)

Converts i to its equivalent character value (for which eq_int_type(i, to_int_type(to_char_type(i))) is true). If i is not equivalent to any character, the behavior is unspecified.

static int_type to_int_type (const char_type& c)

Converts c to its equivalent integer representation.