gpt4 book ai didi

.net - 使用此库 shlwapi.dll 中的 StrCmpLogicalW 函数在 C++ 中自然排序

转载 作者:太空宇宙 更新时间:2023-11-04 14:23:35 44 4
gpt4 key购买 nike

我尝试学习如何使用 StrCmpLogicalW 函数。 C#中有一个帖子 Natural Sort Order in C# .但我正在寻找 C++ 中的语法。

谢谢。

最佳答案

您是说要使用该函数对字符串集合进行排序吗?

bool mycomp(PCWSTR lhs, PCWSTR rhs)
{
return StrCmpLogicalW(lhs,rhs) < 0;
}

或者如果您使用的是 std::wstring :

bool mycomp(const std::wstring & lhs, const std::wstring & rhs)
{
return StrCmpLogicalW(lhs.c_str(),rhs.c_str()) < 0;
}

然后您可以使用该函数调用 std::sort,假设您有一个 std::vector<std::wstring>称为 v:

std::sort(v.begin(), v.end(), mycomp);

关于.net - 使用此库 shlwapi.dll 中的 StrCmpLogicalW 函数在 C++ 中自然排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5780796/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com