std::wcslen

来自cppreference.com
< cpp‎ | string‎ | wide
在标头 <cwchar> 定义
std::size_t wcslen( const wchar_t* str );

返回宽字符串的长度,即空终止宽字符之前的非空宽字符数。

str 所指向的宽字符数组中无空字符则行为未定义。

目录

[编辑] 参数

str - 指向要检验的空终止宽字符串的指针

[编辑] 返回值

空终止宽字符串 str 的长度。

[编辑] 可能的实现

std::size_t wcslen(const wchar_t* start)
{
    // 新手注意:这里并不检查 start 是否是 nullptr!
    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

[编辑] 参阅

返回给定字符串的长度
(函数) [编辑]
返回下一个多字节字符中的字节数
(函数) [编辑]
wcslen 的 C 文档