char_traits Struct

The char_traits struct describes attributes associated with a character.

template <
   class CharType
> struct char_traits;

Parameters

  • CharType
    The element data type.

Remarks

The template struct describes various character traits for type CharType. The template class basic_string as well as several iostream template classes, including basic_ios, use this information to manipulate elements of type CharType. Such an element type must not require explicit construction or destruction. It must supply a default constructor, a copy constructor, and an assignment operator, with the expected semantics. A bitwise copy must have the same effect as an assignment. None of the member functions of struct char_traits can throw exceptions.

Typedefs

char_type

A type of character.

int_type

An integer type that can represent a character of type char_type or an end-of-file (EOF) character.

off_type

An integer type that can represent offsets between positions in a stream.

pos_type

An integer type that can represent positions in a stream.

state_type

A type that represents the conversion state in for multibyte characters in a stream.

Member Functions

assign

Assigns one character value to another.

compare

Compares up to a specified number of characters in two strings.

copy

Copies a specified number of characters from one string to another. Deprecated. Use char_traits::_Copy_s instead.

_Copy_s

Copies a specified number of characters from one string to another.

eof

Returns the end-of-file (EOF) character.

eq

Tests whether two char_type characters are equal.

eq_int_type

Tests whether two characters represented as int_types are equal.

find

Searches for the first occurrence of a specified character in a range of characters.

length

Returns the length of a string.

lt

Tests whether one character is less than another.

move

Copies a specified number of characters in a sequence to another, possible overlapping, sequence. Deprecated. Use char_traits::_Move_s instead.

_Move_s

Copies a specified number of characters in a sequence to another, possible overlapping, sequence.

not_eof

Tests whether a character is the end-of-file (EOF) character.

to_char_type

Converts an int_type character to the corresponding char_type character and returns the result.

to_int_type

Converts a char_type character to the corresponding int_type character and returns the result.

Requirements

Header: <string>

Namespace: std

See Also

Reference

Thread Safety in the C++ Standard Library