std::wmemcmp
From cppreference.com
| ヘッダ <cwchar> で定義 |
||
| int wmemcmp( const wchar_t* lhs, const wchar_t* rhs, std::size_t count ); |
||
lhs と rhs が指すワイド文字配列の最初の count 文字を比較します。比較は辞書順で行われます。
結果の符号は、比較対象の配列で最初に異なるワイド文字のペアの値の差の符号になります。
countがゼロの場合、関数は何も行いません。
目次 |
[編集] パラメータ
| lhs, rhs | - | 比較するワイド文字配列へのポインタ |
| count | - | 検索するワイド文字数 |
[編集] 戻り値
lhs の最初の異なるワイド文字の値が、rhs の対応するワイド文字の値より小さい場合、負の値:lhs は rhs より辞書順で前に来ます。
0 lhs と rhs のすべての count 文字が等しい場合。
lhs の最初の異なるワイド文字の値が、rhs の対応するワイド文字の値より大きい場合、正の値:rhs は lhs より辞書順で前に来ます。
[編集] 注意
この関数はロケールに依存せず、検査する wchar_t オブジェクトの値には注意しません。ヌル文字や無効なワイド文字も比較されます。
[編集] 例
このコードを実行
#include <clocale> #include <cwchar> #include <iostream> #include <locale> #include <string> void demo(const wchar_t* lhs, const wchar_t* rhs, std::size_t sz) { std::wcout << std::wstring(lhs, sz); int rc = std::wmemcmp(lhs, rhs, sz); if (rc == 0) std::wcout << " compares equal to "; else if (rc < 0) std::wcout << " precedes "; else if (rc > 0) std::wcout << " follows "; std::wcout << std::wstring(rhs, sz) << " in lexicographical order\n"; } int main() { std::setlocale(LC_ALL, "en_US.utf8"); std::wcout.imbue(std::locale("en_US.utf8")); wchar_t a1[] = {L'α',L'β',L'γ'}; constexpr std::size_t sz = sizeof a1 / sizeof *a1; wchar_t a2[sz] = {L'α',L'β',L'δ'}; demo(a1, a2, sz); demo(a2, a1, sz); demo(a1, a1, sz); }
実行結果の例
αβγ precedes αβδ in lexicographical order αβδ follows αβγ in lexicographical order αβγ compares equal to αβγ in lexicographical order
[編集] 関連項目
| 2つのワイド文字列を比較する (関数) | |
| 2つのバッファを比較する (関数) | |
| 2つのワイド文字列から指定された文字数を比較する (関数) | |
| C のドキュメント for wmemcmp
| |