首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::strlen

Defined in header <cstring>

std::size_t strlen( const char* str );

返回给定字节字符串的长度,即字符数组中的字符数,该字符数组的第一个元素由str直到并且不包括第一个空字符。如果指向的字符数组中没有空字符,则该行为是未定义的。str...

参数

str

-

pointer to the null-terminated byte string to be examined

返回值

以空结尾的字符串的长度。str...

二次

代码语言:javascript
复制
#include <cstring>
#include <iostream>
 
int main()
{
   const char str[] = "How many characters does this string contain?";
 
   std::cout << "without null character: " << std::strlen(str) << '\n'
             << "with null character: " << sizeof str << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
without null character: 45
with null character: 46

二次

另见

wcslen

returns the length of a wide string (function)

mblen

returns the number of bytes in the next multibyte character (function)

C.strlen文件

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券