std::wcscoll
来自 cppreference.cn
在头文件 <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
|