std::wcslen - cppreference.com
来自cppreference.com
std::size_t wcslen( const wchar_t* 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