std::basic_string::compare
Da cppreference.com.
< cpp | string | basic string
![]() | Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate. La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
int compare(const basic_string& str )const; | (1) | |
int compare( size_type pos1, size_type count1, const basic_string& str )const; | (2) | |
int compare( size_type pos1, size_type count1, const basic_string& str, | (3) | |
int compare(const CharT* s )constnoexcept; | (4) | |
int compare( size_type pos1, size_type count1, const CharT* s )const; | (5) | |
int compare( size_type pos1, size_type count1, const CharT* s, size_type count2 )const; | (6) | |
Confronta due sequenze di caratteri.
1) Original:
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.
You can help to correct and verify the translation. Click here for instructions.
Confronta questa stringa str'. In primo luogo, calcola il numero di caratteri da confrontare, come per size_type rlen =std::min(size(), str.size()). Confronta, poi, chiamando Traits::compare(data(), str.data(), rlen). Per le stringhe standard, questa funzione esegue carattere per carattere di confronto lessicografico. Se il risultato è zero (le stringhe sono uguali finora), quindi le loro dimensioni sono confrontati come segue:
Original:
Compares this string to str. First, calculates the number of characters to compare, as if by size_type rlen =std::min(size(), str.size()). Then compares by calling Traits::compare(data(), str.data(), rlen). For standard strings this function performs character-by-character lexicographical comparison. If the result is zero (the strings are equal so far), then their sizes are compared as follows:
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.
Condition | Result | Return value | |
---|---|---|---|
Traits::compare(data, arg, rlen) < 0 | data is less than arg | <0 | |
Traits::compare(data, arg, rlen) == 0 | size(data) < size(arg) | data is less than arg | <0 |
size(data) == size(arg) | data is equal to arg | 0 | |
size(data) > size(arg) | data is greater than arg | >0 | |
Traits::compare(data, arg, rlen) > 0 | data is greater than arg | >0 |
Confronta una sottostringa
3) [pos1, pos1+count1)
di questa stringa di str' come per basic_string(*this, pos1, count1).compare(str)Original:
Compares a
[pos1, pos1+count1)
substring of this string to str as if by basic_string(*this, pos1, count1).compare(str)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.
Confronta una sottostringa
4) [pos1, pos1+count1)
di questa stringa per una sottostringa [pos2, pas2+count2)
di str' come per basic_string(*this, pos1, count1).compare(basic_string(str, pos2, count2))Original:
Compares a
[pos1, pos1+count1)
substring of this string to a substring [pos2, pas2+count2)
of str as if by basic_string(*this, pos1, count1).compare(basic_string(str, pos2, count2))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.
Confronta questa stringa alla terminazione Null inizio sequenza di caratteri in corrispondenza del carattere puntato da' s, come per compare(basic_string(s))
5) Original:
Compares this string to the null-terminated character sequence beginning at the character pointed to by s, as if by compare(basic_string(s))
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.
Confronta una sottostringa
6) [pos1, pos1+count1)
di questa stringa alla terminazione Null inizio sequenza di caratteri in corrispondenza del carattere puntato da' s, come per basic_string(*this, pos, count1).compare(basic_string(s))Original:
Compares a
[pos1, pos1+count1)
substring of this string to the null-terminated character sequence beginning at the character pointed to by s, as if by basic_string(*this, pos, count1).compare(basic_string(s))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.
Confronta una sottostringa
[pos1, pos1+count1)
di questa stringa di caratteri count2
primi array di caratteri il cui primo carattere è puntato da' s, come per basic_string(*this, pos, count1).compare(basic_string(s, count2)). (Nota: i caratteri da s
s+count2
a possono includere caratteri null))Original:
Compares a
[pos1, pos1+count1)
substring of this string to the first count2
characters of the character array whose first character is pointed to by s, as if by basic_string(*this, pos, count1).compare(basic_string(s, count2)). (Note: the characters from s
to s+count2
may include null characters))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.
Indice |
[modifica]Parametri
str | - | altra stringa da confrontare Original: other string to compare to The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
s | - | puntatore alla stringa di caratteri da confrontare Original: pointer to the character string to compare to The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
count1 | - | numero di caratteri di questa stringa per compore Original: number of characters of this string to compore The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
pos1 | - | posizione del primo carattere in questa stringa da confrontare Original: position of the first character in this string to compare The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
count2 | - | numero di caratteri della stringa specificata compore Original: number of characters of the given string to compore The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
pos2 | - | posizione del primo carattere della stringa data da confrontare Original: position of the first character of the given string to compare The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[modifica]Valore di ritorno
valore negativo se la stringa è meno rispetto alla sequenza di caratteri altra, zero se le due sequenze di caratteri sono uguali, valore positivo se la stringa è superiore rispetto alla sequenza di caratteri altro.
Original:
negative value if this string is less than the other character sequence, zero if the both character sequences are equal, positive value if this string is greater than the other character sequence.
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.
[modifica]Eccezioni
1) 2-6)Può generare le eccezioni generate dai costruttori
basic_string
corrispondenti.Original:
May throw the exceptions thrown by the corresponding
basic_string
constructors.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.
[modifica]Possibile implementazione
template<class CharT, class Traits, class Alloc>int basic_string<CharT, Traits, Alloc>::compare(conststd::basic_string& str)constnoexcept{ size_type lhs_sz = size(); size_type rhs_sz = str.size();int result = traits_type::compare(data(), str.data(), std::min(lhs_sz, rhs_sz));if(result !=0)return result;if(lhs_sz < rhs_sz)return-1;if(lhs_sz > rhs_sz)return1;return0;} |
[modifica]Esempio
This section is incomplete Reason: no example |
[modifica]Vedi anche
confronta due stringhe secondo l'ordine lessicografico (funzione di modello) | |
restituisce una sottostringa (metodo pubblico) | |
definisce il confronto lessicografico e hashing delle stringhe Original: defines lexicographical comparison and hashing of strings The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (classe template) | |
confronta due stringhe in accordo con i parametri locali Original: compares two strings in accordance to the current locale The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (funzione) |