std:: wcsncmp
|
定義済みヘッダー
<cwchar>
|
||
|
int
wcsncmp
(
const
wchar_t
*
lhs,
const
wchar_t
*
rhs,
std::
size_t
count
)
;
|
||
最大で count 個のワイド文字を、2つのヌル終端ワイド文字列で比較します。比較は辞書順で行われます。
結果の符号は、比較対象の文字列において異なる最初のワイド文字の値の差の符号と一致します。
lhs または rhs がヌル終端文字列へのポインタでない場合、動作は未定義です。
目次 |
パラメータ
| lhs, rhs | - | 比較対象のヌル終端ワイド文字列へのポインタ |
| count | - | 比較する最大文字数 |
戻り値
負の値は、 lhs が辞書順で rhs より前に現れることを示します。
lhs と rhs が等しい場合にゼロを返す。
lhs が rhs より辞書順で後に現れる場合、正の値。
例
#include <clocale> #include <cwchar> #include <iostream> #include <locale> void demo(const wchar_t* lhs, const wchar_t* rhs, int sz) { int rc = std::wcsncmp(lhs, rhs, sz); if (rc == 0) std::wcout << "First " << sz << " characters of [" << lhs << "] equal [" << rhs << "]\n"; else if (rc < 0) std::wcout << "First " << sz << " characters of [" << lhs << "] precede [" << rhs << "]\n"; else if (rc > 0) std::wcout << "First " << sz << " characters of [" << lhs << "] follow [" << rhs << "]\n"; } int main() { const wchar_t str1[] = L"안녕하세요"; const wchar_t str2[] = L"안녕히 가십시오"; std::setlocale(LC_ALL, "en_US.utf8"); std::wcout.imbue(std::locale("en_US.utf8")); demo(str1, str2, 5); demo(str2, str1, 8); demo(str1, str2, 2); }
出力:
First 5 characters of [안녕하세요] precede [안녕히 가십시오] First 8 characters of [안녕히 가십시오] follow [안녕하세요] First 2 characters of [안녕하세요] equal [안녕히 가십시오]
関連項目
|
2つの文字列から指定された数の文字を比較する
(関数) |
|
|
2つのワイド文字列を比較する
(関数) |
|
|
2つの配列から指定された数のワイド文字を比較する
(関数) |
|
|
現在のロケールに従って2つのワイド文字列を比較する
(関数) |
|
|
Cドキュメント
for
wcsncmp
|
|