📅  最后修改于: 2020-09-25 09:56:15             🧑  作者: Mango
wcslen() 函数在
size_t wcslen( const wchar_t* str );
wcslen()将以null终止的宽字符串 str
作为参数,并返回其长度。该长度不包括空宽字符 。如果宽字符串没有空宽字符 ,则函数的行为是不确定的。
#include
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.utf8");
wchar_t str1[] = L"Hello World\u0021";
wchar_t str2[] = L"\u0764\u077a\u077c\u079f\u07a1\u072e";
int len1 = wcslen(str1);
int len2 = wcslen(str2);
cout << "Length of str1 = " << len1 << endl;
cout << "Length of str2 = " << len2 << endl;
if (len1 > len2)
cout << "str1 is longer than str2";
else if (len1 < len2)
cout << "str2 is longer than str1";
else
cout << "str1 and str2 are of equal length";
return 0;
}
运行该程序时,输出为:
Length of str1 = 12
Length of str2 = 6
str1 is longer than str2