名稱空間
變體
操作

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)
{
    // NB: start is not checked for 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

[編輯] 參閱

返回給定字串的長度
(函式) [編輯]
返回下一個多位元組字元的位元組數
(函式) [編輯]
C 文件 對應 wcslen