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

std::strcoll

Defined in header <cstring>

int strcoll( const char* lhs, const char* rhs );

对象定义的当前区域设置比较两个以空结尾的字节字符串。LC_COLLATE类别。

参数

lhs, rhs

-

pointers to the null-terminated byte strings to compare

返回值

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

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

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

注记

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

二次

代码语言:javascript
复制
#include <iostream>
#include <cstring>
#include <clocale>
 
int main()
{
    std::setlocale(LC_COLLATE, "cs_CZ.iso88592");
 
    const char* s1 = "hrnec";
    const char* s2 = "chrt";
 
    std::cout << "In the Czech locale: ";
    if(std::strcoll(s1, s2) < 0)
         std::cout << s1 << " before " << s2 << '\n';
    else
         std::cout << s2 << " before " << s1 << '\n';
 
    std::cout << "In lexicographical comparison: ";
    if(std::strcmp(s1, s2) < 0)
         std::cout << s1 << " before " << s2 << '\n';
    else
         std::cout << s2 << " before " << s1 << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
In the Czech locale: hrnec before chrt
In lexicographical comparison: chrt before hrnec

二次

另见

wcscoll

compares two wide 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)

strxfrm

transform a string so that strcmp would produce the same result as strcoll (function)

C.strcoll文件

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

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

扫码关注腾讯云开发者

领取腾讯云代金券