◐ Shell
clean mode source ↗

std::strcmp - cppreference.com

De cppreference.com

Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.

La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí.

Definido en el archivo de encabezado <cstring>

int strcmp( const char *lhs, const char *rhs );

Compara dos cadenas terminadas en null byte. La comparación se realiza lexicográfico .

Original:

Compares two null-terminated byte strings. The comparison is done lexicographically.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Tanto lhs y rhs debe apuntar a cadenas válidas .

Original:

Both lhs and rhs should point to valid strings.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parámetros

lhs, rhs -

punteros a las cadenas de bytes de terminación nula para comparar

Original:

pointers to the null-terminated byte strings to compare

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Valor de retorno

Valor negativo si lhs es menos rhs .

Original:

Negative value if lhs is less than rhs.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

0 lhs si es igual a' rhs .

Original:

0 if lhs is equal to rhs.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Valor positivo si lhs es superior rhs .

Original:

Positive value if lhs is greater than rhs.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Ejemplo

#include <vector>
#include <cstring>
#include <algorithm>
#include <iostream>

int main() 
{
    std::vector<const char*> cats {"Heathcliff", "Snagglepuss", "Hobbes", "Garfield"};
    std::sort(cats.begin(), cats.end(), [](const char *strA, const char *strB) {
        return std::strcmp(strA, strB) < 0;
    }); 

    for (const char *cat : cats) {
        std::cout << cat << '\n';
    }
}

Salida:

Garfield
Heathcliff
Hobbes
Snagglepuss

Ver también