Espaces de noms
Variantes
Actions

std::char_traits

De cppreference.com
< cpp‎ | string

Déclaré dans l'en-tête <string>
template<

    class CharT

>class char_traits;
La classe char_traits définit le flux et les propriétés de fonctionnement d'une chaîne de type caractère, comme des types utilisés pour manipuler les caractères et chaînes de caractères, ainsi que toutes les opérations des communes pour le type de caractère donné .
Original:
The char_traits class defines the stream and string operation properties of a character type, such as the types used for manipulating the characters and character strings, as well as all the common operations for the given character type.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


Il est défini char_traits modèle de classe, qui sert de base pour les instanciations explicites. Elle répond à toutes les exigences du concept de Traits .
Original:
There is class template char_traits defined, which serves as a basis for explicit instantiations. It fulfills all requirements of Traits concept.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
En outre, plusieurs spécialisations sont définies pour la plupart des types de caractères communs qui qui doit spécifier les membres suivants:
Original:
Also, several specializations are defined for most common character types which which has to specify the following members:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Instantiation char_typeint_typeoff_typepos_typestate_type
char_traits<char>charintstreamoffstreamposmbstate_t
char_traits<wchar_t>wchar_twint_twstreamoffwstreamposmbstate_t
char_traits<char16_t> (C++11)char16_tint_least16_tstreamoffu16streamposmbstate_t
char_traits<char32_t> (C++11)char32_tint_least32_tstreamoffu32streamposmbstate_t

Sommaire

[modifier]Types de membres

Type d'
Original:
Type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
char_typeCharT
int_type
un type entier qui peut contenir toutes les valeurs de char_type ainsi EOF
Original:
an integer type that can hold all values of char_type plus EOF
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
off_type
' Définie par l'implémentation
Original:
implementation-defined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pos_type
' Définie par l'implémentation
Original:
implementation-defined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
state_type
' Définie par l'implémentation
Original:
implementation-defined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifier]Fonctions membres

[
statique
Original:
static
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
attribue un caractère
Original:
assigns a character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique statique)[edit]
[
statique
Original:
static
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
compare deux caractères
Original:
compares two characters
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique statique)[edit]
[
statique
Original:
static
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
une séquence de caractères se déplace sur une autre
Original:
moves one character sequence onto another
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique statique)[edit]
[
statique
Original:
static
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
copie d'une séquence de caractères
Original:
copies a character sequence
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique statique)[edit]
[
statique
Original:
static
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
compare lexicographiquement deux séquences de caractères
Original:
lexicographically compares two character sequences
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique statique)[edit]
[
statique
Original:
static
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
renvoie la longueur d'une séquence de caractères
Original:
returns the length of a character sequence
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique statique)[edit]
[
statique
Original:
static
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
finds a character in a character sequence
(fonction membre publique statique)[edit]
[
statique
Original:
static
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
convertit int_type à char_type équivalent
Original:
converts int_type to equivalent char_type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique statique)[edit]
[
statique
Original:
static
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
convertit char_type à int_type équivalent
Original:
converts char_type to equivalent int_type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique statique)[edit]
[
statique
Original:
static
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
compare deux valeurs int_type
Original:
compares two int_type values
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique statique)[edit]
[
statique
Original:
static
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
retourne un' eof valeur
Original:
returns an eof value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique statique)[edit]
[
statique
Original:
static
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
vérifie si un caractère est' eof valeur
Original:
checks whether a character is eof value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique statique)[edit]

[modifier]Exemple

Traits de caractère définies par l'utilisateur peuvent être utilisés pour fournir case-insensitive comparison
Original:
User-defined character traits may be used to provide case-insensitive comparison
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <string>#include <iostream>#include <cctype>   struct ci_char_traits :public std::char_traits<char>{staticbool eq(char c1, char c2){returnstd::toupper(c1)==std::toupper(c2);}staticbool ne(char c1, char c2){returnstd::toupper(c1)!=std::toupper(c2);}staticbool lt(char c1, char c2){returnstd::toupper(c1)<std::toupper(c2);}staticint compare(constchar* s1, constchar* s2, size_t n){while( n--!=0){if(std::toupper(*s1)<std::toupper(*s2))return-1;if(std::toupper(*s1)>std::toupper(*s2))return1;++s1;++s2;}return0;}staticconstchar* find(constchar* s, int n, char a){while( n-->0&&std::toupper(*s)!=std::toupper(a)){++s;}return s;}};   typedefstd::basic_string<char, ci_char_traits> ci_string;   std::ostream& operator<<(std::ostream& os, const ci_string& str){return os.write(str.data(), str.size());}   int main(){ ci_string s1 ="Hello"; ci_string s2 ="heLLo";if(s1 == s2)std::cout<< s1 <<" and "<< s2 <<" are equal\n";}

Résultat :

Hello and heLLo are equal

[modifier]Voir aussi

magasins et manipule des séquences de caractères
Original:
stores and manipulates sequences of characters
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(classe générique)[edit]
close