首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::wcscoll

Defined in header <cwchar>

int wcscoll( const wchar_t* lhs, const wchar_t* rhs );

根据最近安装的区域设置比较两个以空结尾的宽字符串。std::setlocale属性定义的LC_COLLATE类别。

参数

lhs, rhs

-

pointers to the null-terminated wide strings to compare

返回值

负值lhs少于%28先于%29rhs...

​0​如果lhs等于rhs...

正值lhs大于%28跟随%29rhs...

注记

排序顺序是字典顺序:字母在国家字母中的位置等价类%29比它的情况或变体有更高的优先级。在等价类中,小写字符在大写等价物和特定于地区的顺序之前进行排序,可以适用于具有对话式的字符。在某些地区,一组字符比较起来是单个的。校对单位例如,"ch"捷克文如下"h"先于"i",和"dzs"匈牙利文如下"dz"先于"g"...

二次

代码语言:javascript
复制
#include <iostream>
#include <clocale>
 
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");
}

二次

产出:

二次

代码语言:javascript
复制
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

二次

另见

strcoll

compares two strings in accordance to the current locale (function)

do_compare virtual

compares two strings using this facet's collation rules (virtual protected member function of std::collate)

wcsxfrm

transform a wide string so that wcscmp would produce the same result as wcscoll (function)

C文件

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券