名前空間
変種
操作

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

提供: cppreference.com
< cpp‎ | string‎ | char traits
(Fix some translations)
 
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}}
 
{{dcl begin}}
 
{{dcl begin}}
{{dcl |  
+
{{dcl
int compare( const CharT* lhs, const CharT* rhs, std::size_t count );
+
|
 +
int compare( const * , const * , std::size_t count );
 
}}
 
}}
 +
 +
 +
 +
 
{{dcl end}}
 
{{dcl 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}}
 +
 
 +
{{tt|}}
  
===パラメータ===
+
======
 
{{par begin}}
 
{{par begin}}
{{par | lhs, rhs |{{tr| 比較する文字列へのポインタ| pointers to character strings to compare}}}}
+
{{par | , | }}
{{par | count |{{tr| 各文字列から比較する文字の数| the number of characters to compare from each character string}}}}
+
{{par | count | }}
 
{{par end}}
 
{{par end}}
  
===値を返します===
+
======
{{tr|{{tt|lhs}}場合は、負の値は''''{{tt|rhs}}より小さい.|Negative value if {{tt|lhs}} is ''less than'' {{tt|rhs}}.}}
+
{{tt|}} {{tt|}} ''''
  
{{tr|{{c|0}}場合{{tt|lhs}}です''等しい''{{tt|rhs}}.|{{c|0}} if {{tt|lhs}} is ''equal to'' {{tt|rhs}}.}}
+
{{|}} {{tt|}} ''等しい''{{c|0}}
  
{{tr|正の値の場合{{tt|lhs}}''''より大きい{{tt|rhs}}.|Positive value if {{tt|lhs}} is ''greater than'' {{tt|rhs}}.}}
+
{{tt|}} {{tt|}} ''''
  
 
===例外===
 
===例外===
 
(なし)
 
(なし)
  
===複雑性===
+
======
{{tr|リニア.|Linear.}}
+
{{|}}
  
 
[[de:cpp/string/char traits/compare]]
 
[[de:cpp/string/char traits/compare]]

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 に比例。