Espacios de nombres
Variantes
Acciones

std::basic_string::compare

De cppreference.com
< cpp‎ | string‎ | basic string
 
 
Strings biblioteca
Terminadas en nulo
Original:
Null-terminated strings
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cadenas de bytes
Multibyte cuerdas
Cadenas anchas
Clases
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
std::basic_string
Las funciones miembro
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Elemento acceso
Original:
Element access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los iteradores
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Capacidad
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Operaciones
Original:
Operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::compare
Buscar
Original:
Search
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Constantes
Original:
Constants
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Terceros funciones
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)(C++11)(C++11)
(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
Clases de ayuda
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
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,

             size_type pos2, size_type count2 ) const;
(3)
int compare( const CharT* s ) const noexcept;
(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 dos secuencias de caracteres .
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.
1)
Compara esta cadena str'. En primer lugar, se calcula el número de caracteres a comparar, como por size_type rlen = std::min(size(), str.size()). Luego compara llamando Traits::compare(data(), str.data(), rlen). Para las cadenas estándar esta función realiza carácter por carácter lexicográfico comparación. Si el resultado es cero (las cadenas son iguales hasta el momento), entonces sus tamaños se comparan como sigue:
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.
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
2)
Compara una subcadena [pos1, pos1+count1) de esta cadena str' como 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.
3)
Compara una subcadena [pos1, pos1+count1) de esta cadena a una subcadena de [pos2, pas2+count2)' str como 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.
4)
Compara esta cadena al comienzo caracteres terminada en nulo en la secuencia de caracteres apuntada por' s, como por compare(basic_string(s))
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.
5)
Compara una subcadena [pos1, pos1+count1) de esta cadena para el inicio caracteres terminada en nulo en la secuencia de caracteres apuntada por' s, como 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.
6)
Compara una subcadena [pos1, pos1+count1) de esta cadena con los caracteres count2 primero de la matriz de caracteres cuyo primer carácter es apuntado por' s, como por basic_string(*this, pos, count1).compare(basic_string(s, count2)). (Nota: los personajes de s a s+count2 pueden 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.

Contenido

[editar] Parámetros

str -
otra cadena a 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 -
puntero a la cadena de caracteres a 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 de esta cadena 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 -
posición del primer carácter en esta cadena 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 de la cadena dada 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 -
posición del primer carácter de la cadena 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 si esta cadena es menor' de la secuencia de otro carácter, cero si las secuencias de caracteres de ambos son igual valor, positivo si esta cadena es mayor' de la secuencia de caracteres de otro .
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.

[editar] Excepciones

1)
noexcept specification:  
noexcept
  (desde C++11)
2-6)
Puede lanzar las excepciones producidas por los constructores basic_string correspondientes .
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.

[editar] Posible implementación

template<class CharT, class Traits, class Alloc>
int basic_string<CharT, Traits, Alloc>::compare(const std::basic_string& str) const noexcept
{
    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)
        return 1;
    return 0;
}

[editar] Ejemplo

[editar] Ver también

comparación lexicográfica de dos cadenas de texto
(plantilla de función) [editar]
devuelve una subcadena
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.

(función miembro público) [editar]
define comparación lexicográfica y hash de cadenas
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.

(plantilla de clase) [editar]
compara dos cadenas de acuerdo a la localización actual
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.

(función) [editar]