📅  最后修改于: 2020-09-25 09:51:38             🧑  作者: Mango
wcscoll() 函数在
int wcscoll( const wchar_t* lhs, const wchar_t* rhs );
wcscoll() 函数采用两个参数: lhs
和rhs
。它根据LC_COLLATE类别的当前语言环境比较lhs
和rhs
的内容。
wcscoll() 函数返回:
#include
#include
#include
using namespace std;
void compare(const wchar_t* p1, const wchar_t* p2)
{
if(wcscoll(p1, p2) < 0)
wcout << p1 << L" precedes " << p2 << '\n';
else if (std::wcscoll(p1, p2) > 0)
wcout << p2 << L" precedes " << p1 << '\n';
else
wcout << p2 << L" equals " << p1 << '\n';
}
int main()
{
wchar_t str1[] = L"årtist";
wchar_t str2[] = L"äpple";
setlocale(LC_ALL, "en_US.utf8");
wcout << L"In the American locale: ";
compare(str1, str2);
setlocale(LC_ALL, "sv_SE.utf8");
wcout << L"In the Swedish locale: ";
compare(str1, str2);
return 0;
}
运行该程序时,输出为:
In the American locale: äpple precedes årtist
In the Swedish locale: årtist precedes äpple