C++ 中的wcslen() 函数返回给定宽字符串的长度。
wcslen() 函数在<cwchar> 头文件中定义。
wcslen()原型
size_t wcslen( const wchar_t* str );
wcslen() 以空终止的宽字符串 str
作为其参数并返回其长度。长度不包括空宽字符。如果宽字符串中没有空宽字符,则函数的行为未定义。
参数:
str
:指向要计算其长度的空终止宽字符串的指针。
返回:
- wcslen() 函数返回空终止的宽字符串的长度。
示例:wcslen() 函数如何工作?
#include <cwchar>
#include <clocale>
#include <iostream>
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
相关用法
- C++ wcslen()用法及代码示例
- C++ wcstold()用法及代码示例
- C++ wcsftime()用法及代码示例
- C++ wcstod()用法及代码示例
- C++ wcscspn()用法及代码示例
- C++ wcsncmp()用法及代码示例
- C++ wcstok()用法及代码示例
- C++ wcsstr()用法及代码示例
- C++ wcsrchr()用法及代码示例
- C++ wcsncpy()用法及代码示例
- C++ wcsspn()用法及代码示例
- C++ wcschr()用法及代码示例
- C++ wcstof()用法及代码示例
- C++ wcstol()用法及代码示例
- C++ wcspbrk()用法及代码示例
- C++ wcscat()用法及代码示例
- C++ wcscoll()用法及代码示例
- C++ wcsncat()用法及代码示例
- C++ wcscpy()用法及代码示例
- C++ wcsxfrm()用法及代码示例
注:本文由纯净天空筛选整理自 C++ wcslen()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。