std:: wcslen
From cppreference.net
C++
Text processing library
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
Null-terminated wide strings
| Functions | ||||||||||||||||||||||||||
| Character classification | ||||||||||||||||||||||||||
| Character manipulation | ||||||||||||||||||||||||||
| Conversions to numeric formats | ||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||
| String manipulation | ||||||||||||||||||||||||||
| String examination | ||||||||||||||||||||||||||
| Array manipulation | ||||||||||||||||||||||||||
|
定义于头文件
<cwchar>
|
||
|
std::
size_t
wcslen
(
const
wchar_t
*
str
)
;
|
||
返回宽字符串的长度,即终止空宽字符之前的非空宽字符数量。
如果由 str 所指向的宽字符数组中不存在空字符,则行为是未定义的。
目录 |
参数
| str | - | 指向待检测的以空字符结尾的宽字符串的指针 |
返回值
以空字符结尾的宽字符串 str 的长度。
可能的实现
std::size_t wcslen(const wchar_t* start) { // 注意:未对start进行空指针检查! const wchar_t* end = start; while (*end != L'\0') ++end; return end - start; } |
示例
运行此代码
#include <iostream> #include <cwchar> int main() { const wchar_t* str = L"Hello, world!"; std::wcout << "The length of L\"" << str << "\" is " << std::wcslen(str) << '\n'; }
输出:
The length of L"Hello, world!" is 13
参见
|
返回给定字符串的长度
(函数) |
|
|
返回下一个多字节字符的字节数
(函数) |
|
|
C documentation
for
wcslen
|
|