📅  最后修改于: 2023-12-03 14:59:36.141000             🧑  作者: Mango
wcsncmp()是C/C++标准库中的一个函数,用于比较两个宽字符字符串的前n个字符。它返回一个整数来表示比较结果。
int wcsncmp(const wchar_t* str1, const wchar_t* str2, size_t n);
#include <wchar.h>
#include <stdio.h>
int main() {
wchar_t str1[] = L"Hello";
wchar_t str2[] = L"World";
int result = wcsncmp(str1, str2, 3);
if (result < 0) {
wprintf(L"%ls is less than %ls\n", str1, str2);
} else if (result > 0) {
wprintf(L"%ls is greater than %ls\n", str1, str2);
} else {
wprintf(L"%ls is equal to %ls\n", str1, str2);
}
return 0;
}
输出:
Hel is less than Wor