名前空間
変種
操作

「cpp/string/char traits/compare」の版間の差分

提供: cppreference.com
< cpp‎ | string‎ | char traits
(Translated from the English version using Google Translate)
 
 
(2人の利用者による、間の4版が非表示)
1行: 1行:
{{tr_note}}
 
 
{{cpp/string/char_traits/title|compare}}
 
{{cpp/string/char_traits/title|compare}}
 
{{cpp/string/char_traits/navbar}}
 
{{cpp/string/char_traits/navbar}}
{{ddcl list begin}}
+
{{begin}}
{{ddcl list item |  
+
{{
int compare( const CharT* lhs, const CharT* rhs, std::size_t count );
+
|
 +
int compare( const * , const * , std::size_t count );
 
}}
 
}}
{{ddcl list end}}
+
{{
 +
 +
 +
 +
end}}
  
{{tr|文字列の最初の{{tt|count}}の文字を比較{{tt|lhs}}と{{tt|rhs}}。比較は辞書順で行われ.|Compares the first {{tt|count}} characters of the character strings {{tt|lhs}} and {{tt|rhs}}. The comparison is done lexicographically.}}
+
{{tt|}} と {{tt|}} {{tt|count}}
  
===パラメータ===
+
{{|count}}
{{param list begin}}
+
{{param list item | lhs, rhs |{{tr| 比較する文字列へのポインタ| pointers to character strings to compare}}}}
+
{{param list item | count |{{tr| 各文字列から比較する文字の数| the number of characters to compare from each character string}}}}
+
{{param list end}}
+
  
===値を返します===
+
======
{{tr|{{tt|lhs}}場合は、負の値は''''{{tt|rhs}}より小さい.|Negative value if {{tt|lhs}} is ''less than'' {{tt|rhs}}.}}
+
{{}}
 +
{{| }}
 +
{{| }}
 +
{{}}
  
{{tr|{{c|0}}場合{{tt|lhs}}です''等しい''{{tt|rhs}}.|{{c|0}} if {{tt|lhs}} is ''equal to'' {{tt|rhs}}.}}
+
 +
{{tt|}} {{tt|}} ''''
  
{{tr|正の値の場合{{tt|lhs}}''''より大きい{{tt|rhs}}.|Positive value if {{tt|lhs}} is ''greater than'' {{tt|rhs}}.}}
+
{{|{{tt|}} ''''{{|}}
 +
 
 +
{{tt|}} {{tt|}}
  
 
===例外===
 
===例外===
{{tr|(なし)|(none)}}
+
 +
 
 +
 +
{{|}}
  
===複雑===
+
{{tr|リニア.|Linear.}}
+
 +
 +
 +
 +
 +
 +

2018年6月15日 (金) 11:37時点における最新版

static int compare( const char_type* s1, const char_type* s2, std::size_t count );
(C++17未満)
static constexpr int compare( const char_type* s1, const char_type* s2, std::size_t count );
(C++17以上)

文字列 s1s2 の最初の count 個の文字を比較します。 比較は辞書的に行われます。

count がゼロの場合、文字列は等しいとみなされます。

目次

[編集] 引数

s1, s2 - 比較する文字列を指すポインタ
count - それぞれの文字列からの比較する文字数

[編集] 戻り値

s1s2 より小さい場合は負の値。

s1s2等しい場合は 0

s1s2 より大きい場合は正の値。

[編集] 例外

(なし)

[編集] 計算量

count に比例。