C/C中的wmemcmp()函数++

这个 wmemcmp() 函数比较两个宽字符。此函数比较第一个 号码 两个宽字符的宽字符,由 str1 str2 ,如果两个字符串的值相等或不相等,则返回零。

null

语法:

int wmemcmp(常量wchar_t*str1,常量wchar_t*str2,大小\u t num);

参数:

  • str1: 指定指向第一个字符串的指针。
  • str2: 指定指向第二个字符串的指针。
  • 号码: 指定要比较的字符数。

返回值: 此函数返回三个不同的值,它们定义了两个字符串之间的关系:

  • :当两个字符串相等时。
  • 正值 :当两个字符串中不匹配的第一个宽字符在str1中的频率高于在str2中的频率时。
  • 负值 :当两个字符串中不匹配的第一个宽字符在str1中的频率低于在str2中的频率时

以下程序说明了上述功能:

项目1:

// C++ program to illustrate
// wmemcmp() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// initialize two strings
wchar_t str1[] = L "geekforgeeks" ;
;
wchar_t str2[] = L "geekforgeeks" ;
// this function will compare these two strings
// till 12 characters, if there would have been
// more than 12 characters, it will compare
// even more than the length of the strings
int print = wmemcmp(str1, str2, 12);
// print if it's equal or not equal( greater or smaller)
wprintf(L "wmemcmp comparison: %ls" ,
print ? L "not equal" : L "equal" );
return 0;
}


输出:

wmemcmp comparison: equal

项目2:

// C++ program to illustrate
// wmemcmp() function
// Comparing two strings with the same type of function
// wcsncmp() and wmemcmp()
#include <bits/stdc++.h>
using namespace std;
int main()
{
// initialize two strings
wchar_t str1[] = L "geekforgeeks" ;
;
wchar_t str2[] = L "geekforgeeks" ;
// wcsncmp() function compare characters
// until the null character is encountered (' ')
int first = wcsncmp(str1, str2, 20);
// but wmemcmp() function compares 20 characters
// even after encountering null character
int second = wmemcmp(str1, str2, 20);
// print if it's equal or not equal( greater or smaller)
wprintf(L "wcsncmp comparison: %ls" ,
first ? L "not equal" : L "equal" );
wprintf(L "wmemcmp comparison: %ls" ,
second ? L "not equal" : L "equal" );
return 0;
}


输出:

wcsncmp comparison: equal
wmemcmp comparison: not equal

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享