命名空间
变体
操作

std::wcscoll

来自 cppreference.cn
< cpp‎ | string‎ | wide
定义于头文件 <cwchar>
int wcscoll( const wchar_t* lhs, const wchar_t* rhs );

根据 std::setlocale 最近安装的,由 LC_COLLATE 类别定义的区域设置,比较两个空终止宽字符串。

目录

[edit] 参数

lhs, rhs - 指向要比较的空终止宽字符串的指针

[edit] 返回值

如果 lhs 小于(先于) rhs,则为负值。

0 如果 lhs 等于 rhs

如果 lhs 大于(后于) rhs,则为正值。

[edit] 注意

排序规则是字典顺序:字母在国家字母表中的位置(其等价类)比其大小写或变体具有更高的优先级。在等价类中,小写字符的排序先于其大写等效项,并且特定于区域设置的顺序可能适用于带有变音符号的字符。在某些区域设置中,字符组比较为单个排序单元。例如,捷克语中的 "ch" 位于 "h" 之后,"i" 之前;匈牙利语中的 "dzs" 位于 "dz" 之后,"g" 之前。

[edit] 示例

#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

[edit] 参见

根据当前区域设置比较两个字符串
(函数) [edit]
[虚拟]
使用此 facet 的排序规则比较两个字符串
(std::collate<CharT> 的虚拟保护成员函数) [edit]
转换宽字符串,以便 wcscmp 产生与 wcscoll 相同的结果
(函数) [edit]
C 文档 关于 wcscoll 的文档