◐ Shell
clean mode source ↗

std::basic_string::compare – cppreference.com

Aus cppreference.com

<metanoindex/>

<tbody> </tbody>

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)

Vergleicht zwei Zeichenfolgen .

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)

Vergleicht diese Zeichenfolge str. Zuerst berechnet die Anzahl der Zeichen zu vergleichen, als ob durch size_type rlen = std::min(size(), str.size()). Dann vergleicht indem Traits::compare(data(), str.data(), rlen). Für Standard-Strings diese Funktion führt Charakter-Charakter lexikographische Vergleich. Wenn das Ergebnis Null ist (die Saiten gleich sind bisher), dann ihre Größen sind wie folgt verglichen:

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)

Vergleicht einen [pos1, pos1+count1) Teilzeichenfolge dieser Zeichenfolge str wie von 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)

Vergleicht einen [pos1, pos1+count1) Teilzeichenfolge dieser String in einen Teilstring [pos2, pas2+count2) von str wie von 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)

Vergleicht diese Zeichenfolge an den null-terminierte Zeichenfolge Beginn auf den Charakter, auf die s, als ob durch 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)

Vergleicht einen [pos1, pos1+count1) Teilzeichenfolge dieser Zeichenfolge an den null-terminierte Zeichenfolge Beginn auf den Charakter, auf die s, als ob durch 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)

Vergleicht einen [pos1, pos1+count1) Teilzeichenfolge dieser String in der ersten count2 Zeichen des Zeichen-Array, dessen erstes Zeichen wird durch s hingewiesen, als ob durch basic_string(*this, pos, count1).compare(basic_string(s, count2)). (Hinweis: die Zeichen aus s um s+count2 kann NULL-Zeichen enthalten))

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.

Parameter

str -

anderen Zeichenfolge zu vergleichen

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 -

Zeiger auf die Zeichenfolge zu vergleichen

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 -

Anzahl der Zeichen dieser Zeichenfolge 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 -

Position des ersten Zeichens in dieser Zeichenfolge zu vergleichen

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 -

Anzahl der Zeichen des angegebenen String 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 -

Position des ersten Zeichens eines gegebenen Strings zu vergleichen

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.

Rückgabewert

negativen Wert, wenn diese Zeichenfolge ist weniger als die andere Zeichenfolge, Null, wenn die beiden Zeichenfolgen gleich, positiven Wert sind, wenn diese Zeichenfolge ist mehr als der andere Zeichenfolge .

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.

Ausnahmen

1)

2-6)

Können die Ausnahmen von den entsprechenden basic_string Konstruktoren geworfen werfen .

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.

Mögliche Implementierung

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;
}

Beispiel

Siehe auch

vergleicht lexikographisch zwei Strings
(Funktions-Template) [edit]

liefert einen Teilstring

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.


(öffentliche Elementfunktion) [edit]

definiert lexikographische Vergleich und Hashing von 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.


(Klassen-Template) [edit]

vergleicht zwei Strings in Übereinstimmung mit dem aktuellen Gebietsschema

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.


(Funktion) [edit]