std::char_traits
Aus cppreference.com
![]() | This page has been machine-translated from the English version of the wiki using Google Translate. The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
definiert in Header <string> | ||
template< class CharT | ||
Die
char_traits
Klasse definiert den Strom-und String-Betrieb Eigenschaften eines Charakter-Typ, wie die Typen für die Manipulation der Zeichen und Zeichenketten, sowie alle die gemeinsamen Operationen für den gegebenen Charakter-Typ verwendet .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.
You can help to correct and verify the translation. Click here for instructions.
Es gibt Klassen-Template
char_traits
definiert, die als Grundlage für die explizite Instantiierung dient. Es erfüllt alle Anforderungen der Traits
Konzept .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.
You can help to correct and verify the translation. Click here for instructions.
Auch mehrere Spezialisierungen für die meisten gängigen Arten von Zeichen, die das hat folgende Mitglieder festlegen definiert:
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.
You can help to correct and verify the translation. Click here for instructions.
Instantiation | char_type | int_type | off_type | pos_type | state_type |
---|---|---|---|---|---|
char_traits<char> | char | int | streamoff | streampos | mbstate_t |
char_traits<wchar_t> | wchar_t | wint_t | wstreamoff | wstreampos | mbstate_t |
char_traits<char16_t>(C++11) | char16_t | int_least16_t | streamoff | u16streampos | mbstate_t |
char_traits<char32_t>(C++11) | char32_t | int_least32_t | streamoff | u32streampos | mbstate_t |
This section is incomplete Reason: simplify the description, emphasize that char_traits can be user defined |
Inhaltsverzeichnis |
[Bearbeiten]Mitglied Typen
Type 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_type | CharT |
int_type | ein Integer-Typ, der alle Werte des char_type halten kann und 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 | Implementierung definiert 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 | Implementierung definiert 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 | Implementierung definiert 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. |
[Bearbeiten]Member-Funktionen
[statisch] | weist einen Charakter 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. (public static Elementfunktion) |
[statisch] | vergleicht zwei Zeichen 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. (public static Elementfunktion) |
[statisch] | bewegt sich ein Zeichenfolge auf eine andere 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. (public static Elementfunktion) |
[statisch] | kopiert eine Zeichenkette 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. (public static Elementfunktion) |
[statisch] | lexikographisch vergleicht zwei Zeichenfolgen 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. (public static Elementfunktion) |
[statisch] | gibt die Länge einer Zeichensequenz 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. (public static Elementfunktion) |
[statisch] | finds a character in a character sequence (public static Elementfunktion) |
[statisch] | wandelt int_type gleichwertige char_type 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. (public static Elementfunktion) |
[statisch] | wandelt char_type gleichwertige int_type 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. (public static Elementfunktion) |
[statisch] | vergleicht zwei int_type WerteOriginal: compares two int_type valuesThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (public static Elementfunktion) |
[statisch] | gibt ein eof Wert 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. (public static Elementfunktion) |
[statisch] | prüft, ob ein Zeichen eof Wert ist 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. (public static Elementfunktion) |
[Bearbeiten]Beispiel
Benutzer-definierte Zeichen Merkmale können verwendet werden, um case-insensitive comparison bereitzustellen
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.
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";}
Output:
Hello and heLLo are equal
[Bearbeiten]Siehe auch
speichert und bearbeitet Sequenzen von Zeichen 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. (Klassen-Template) |