名前空間
変種
操作

std::basic_string::compare

提供: cppreference.com
< cpp‎ | string‎ | basic string

 
 
 
std::basic_string
 
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)
2つの文字シーケンスを比較.
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)
のstrにこの文字列を比較します。まず、size_type rlen = std::min(size(), str.size())の場合と同様にして、比較する文字の数を計算します。その後Traits::compare(data(), str.data(), rlen)を呼び出して比較します。標準の文字列の場合、この関数は、文字ごとに比較を辞書式が実行されます。結果がゼロ(文字列がこれまでに等しい)である場合、それらのサイズは以下のように比較されます
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)
まるで[pos1, pos1+count1)によって strにこの文字列の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)
[pos1, pos1+count1) strのまるで[pos2, pas2+count2)により部分文字列にこの文字列の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)
としてcompare(basic_string(s))であれば、 'のが指す文字で、NULLで終わる文字シーケンスの先頭にこの文字列を比較します
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)
として[pos1, pos1+count1)であれば、 'のが指す文字で、NULLで終わる文字シーケンスの先頭にこの文字列の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)
):([pos1, pos1+count1)count2から文字がヌル文字を含めることができます注)最初の文字 'のとしてbasic_string(*this, pos, count1).compare(basic_string(s, count2)).によって場合によって指された文字配列の最初のs文字にこの文字列のs+count2の部分文字列を比較します
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.

目次

[編集] パラメータ

str -
と比較するもう一方の文字列
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 -
と比較する文字列へのポインタ
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 -
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 -
比較するには、この文字列の最初の文字の位置
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 -
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 -
比較するために与えられた文字列の最初の文字の位置
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.

[編集] 値を返します

この文字列が他の文字シーケンスより大きいのであれば両方の文字のシーケンスが等しい正の値である場合、この文字列が他の文字配列よりも少ない'、ゼロの場合は負の値.
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.

[編集] 例外

1)
noexcept 指定:  
noexcept
  (C++11およびそれ以降)
2-6)
対応basic_stringコンストラクタによってスローされた例外をスローすることがあります.
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.

[編集] 可能な実装

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

[編集]

[編集] 参照

2つの文字列を辞書的に比較します
(関数テンプレート) [edit]
部分文字列を返します
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.

(パブリックメンバ関数) [edit]
文字列の比較とハッシュを辞書式が定義されています
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.

(クラステンプレート) [edit]
現在のロケールに従って2つの文字列を比較します
(関数) [edit]