std::wcscoll
來自 cppreference.com
在標頭檔案 <cwchar> 中定義 |
||
int wcscoll( const wchar_t* lhs, const wchar_t* rhs ); |
||
根據 LC_COLLATE 類別,使用最近由 std::setlocale 安裝的區域設定比較兩個以空字元結尾的寬字串。
目錄 |
[編輯] 引數
lhs, rhs | - | 指向要比較的以空字元結尾的寬字串的指標 |
[編輯] 返回值
如果 lhs 小於(在前面) rhs,則返回負值。
如果 lhs 等於 rhs,則返回 0。
如果 lhs 大於(在後面) rhs,則返回正值。
[編輯] 注意
排序順序是字典順序:字母在國家字母表中的位置(其 等價類)具有比其大小寫或變體更高的優先順序。在等價類中,小寫字元在對應的大寫字元之前排序,並且特定於區域設定的順序可能適用於帶變音符號的字元。在某些區域設定中,字元組作為一個 排序單元 進行比較。例如,捷克語中的 "ch" 位於 "h" 之後,"i" 之前;匈牙利語中的 "dzs" 位於 "dz" 之後,"g" 之前。
[編輯] 示例
執行此程式碼
#include <clocale> #include <iostream> void try_compare(const wchar_t* p1, const wchar_t* p2) { if (std::wcscoll(p1, p2) < 0) std::wcout << p1 << " before " << p2 << '\n'; else std::wcout << p2 << " before " << p1 << '\n'; } int main() { std::setlocale(LC_ALL, "en_US.utf8"); std::wcout << "In the American locale: "; try_compare(L"hrnec", L"chrt"); std::setlocale(LC_COLLATE, "cs_CZ.utf8"); std::wcout << "In the Czech locale: "; try_compare(L"hrnec", L"chrt"); std::setlocale(LC_COLLATE, "en_US.utf8"); std::wcout << "In the American locale: "; try_compare(L"år", L"ängel"); std::setlocale(LC_COLLATE, "sv_SE.utf8"); std::wcout << "In the Swedish locale: "; try_compare(L"år", L"ängel"); }
輸出
In the American locale: chrt before hrnec In the Czech locale: hrnec before chrt In the American locale: ängel before år In the Swedish locale: år before ängel
[編輯] 另請參閱
根據當前區域設定比較兩個字串 (函式) | |
[virtual] |
使用此 facet 的排序規則比較兩個字串 ( std::collate<CharT> 的虛保護成員函式) |
轉換寬字串,使 wcscmp 產生與 wcscoll 相同的結果(函式) | |
C 文件 為 wcscoll
|