std::basic_string::compare
Da cppreference.com
< cpp | string | basic string
![]() | 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. |
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) | |
Compara duas sequências de caracteres.
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.
Compara essa string para' str. Primeiro, calcula o número de caracteres para comparar, como se por size_type rlen =std::min(size(), str.size()). Em seguida, compara chamando Traits::compare(data(), str.data(), rlen). Para strings padrão esta função realiza caractere por caractere-lexicográfica comparação. Se o resultado for igual a zero (as cordas são iguais até agora), em seguida, os seus tamanhos são comparadas como se 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 |
Compara uma substring
3) [pos1, pos1+count1)
dessa seqüência para str', como se por 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.
Compara uma substring
4) [pos1, pos1+count1)
dessa seqüência para uma substring [pos2, pas2+count2)
de str como se por 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.
Compara essa string para o início seqüência terminada em nulo personagem no caráter apontado por' s, como se por 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.
Compara uma substring
6) [pos1, pos1+count1)
dessa seqüência para o início seqüência terminada em nulo personagem no caráter apontado por' s, como se por 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.
Compara uma substring
[pos1, pos1+count1)
desta cadeia para os personagens count2
primeiro da matriz de caracteres cujo primeiro caractere é apontado por' s, como se por basic_string(*this, pos, count1).compare(basic_string(s, count2)). (Nota: os personagens de s
para s+count2
podem incluir caracteres nulos))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.
Índice |
[editar]Parâmetros
str | - | outra seqüência para comparar 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 | - | ponteiro para a cadeia de caracteres para comparar 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 | - | número de caracteres desta string para 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 | - | posição do primeiro caractere nesta seqüência para comparar 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 | - | número de caracteres da seqüência de determinado 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 | - | posição do primeiro caractere da string dada para comparar 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. |
[editar]Valor de retorno
valor negativo se essa seqüência é menos do que a seqüência de outro personagem, zero se as seqüências de ambos os personagens são de valor, igual positivo se esta string é maior do que a sequência de caracteres de outros.
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.
[editar]Exceções
1) 2-6)Pode lançar as exceções lançadas pelos construtores
basic_string
correspondentes.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.
[editar]Possível implementação
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;} |
[editar]Exemplo
Esta seção está incompleta Motivo: sem exemplo |
[editar]Veja também
lexicographically compara duas strings Original: lexicographically compares two strings The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (modelo de função) | |
retorna uma substring Original: returns a substring The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
define lexicográfica comparação e hash de strings 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. (modelo de classe) | |
compara duas seqüências de acordo com a localidade 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. (função) |