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

std::wcscmp

Defined in header <cwchar>

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

按字典顺序比较两个以空结尾的宽字符串。

结果的符号是所比较的字符串中第一对宽字符的值之间差异的符号。

如果lhsrhs不是指向以空结尾的宽字符串的指针。

参数

lhs, rhs

-

pointers to the null-terminated wide strings to compare

返回值

负值lhs出现在前面rhs按字典顺序排列。

零中频lhsrhs比较平等。

正值lhs出现在rhs按字典顺序排列。

注记

此函数不区分区域设置,不像std::wcscoll,如果同时使用不同Unicode块中的字符,或者当代码单元的顺序与排序规则顺序不匹配时,则该顺序可能没有意义。

二次

代码语言:javascript
复制
#include <vector>
#include <cwchar>
#include <algorithm>
#include <iostream>
 
int main()
{
    std::vector<const wchar_t*> leaders{L"Ленин", L"Сталин", L"Маленков",
        L"Хрущёв", L"Брежнев", L"Андропов", L"Черненко", L"Горбачёв"};
 
    std::sort(leaders.begin(), leaders.end(), [](auto strA, auto strB) {
        return std::wcscmp(strA, strB) < 0;
    });
 
    std::setlocale(LC_ALL, "en_US.utf8");
    std::wcout.imbue(std::locale("en_US.utf8"));
    for (auto leader : leaders)
        std::wcout << leader << '\n';
}

二次

可能的产出:

二次

代码语言:javascript
复制
Андропов
Брежнев
Горбачёв
Ленин
Маленков
Сталин
Хрущёв
Черненко

二次

另见

wcsncmp

compares a certain amount of characters from two wide strings (function)

wmemcmp

compares a certain amount of wide characters from two arrays (function)

strcmp

compares two strings (function)

wcscoll

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

c wcscmp文档

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

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

扫码关注腾讯云开发者

领取腾讯云代金券