📅  最后修改于: 2020-09-25 10:13:44             🧑  作者: Mango
wmemcmp() 函数在
int wmemcmp( const wchar_t* lhs, const wchar_t* rhs, size_t count );
wmemcmp() 函数采用三个参数: lhs
, rhs
和count
。此函数按字典顺序比较lhs
和rhs
的第一个计数宽字符 。
wmemcmp() 函数返回:
#include
#include
#include
using namespace std;
void compare(wchar_t *lhs, wchar_t *rhs, int count)
{
int result = wmemcmp(lhs, rhs, count);
if(result > 0)
wcout << rhs << L" precedes " << lhs << endl;
else if (result < 0)
wcout << lhs << L" precedes " << rhs << endl;
else
wcout << L"First " << count << L" characters of " << lhs << L" and " << rhs << L" are same" << endl;
}
int main()
{
setlocale(LC_ALL, "en_US.utf8");
wchar_t lhs[] = L"\u0386\u03a6\u03aa\u03ac\u03c8\u03c9\u03ee";
wchar_t rhs[] = L"\u0386\u03a6\u03aa\u03ac\u03c0\u03c7\u03fb";
compare(lhs, rhs, 4);
compare(lhs, rhs, 7);
return 0;
}
运行该程序时,输出为:
First 4 characters of ΆΦΪάψωϮ and ΆΦΪάπχϻ are same
ΆΦΪάπχϻ precedes ΆΦΪάψωϮ