std::strcoll
STD::strcoll
Defined in header | | |
---|---|---|
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"
...
例
二次
#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';
}
二次
产出:
二次
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文件
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。