strlen函数用于获取字符串的长度,即字符串中字符的个数(不包括字符串末尾的空字符’’)
strlen函数用于获取字符串的长度,即字符串中字符的个数(不包括字符串末尾的空字符’\0’)。其用法如下:
#include<cstring>
size_tstrlen(constchar*str);
其中,参数str
是要获取长度的字符串,返回值是该字符串中字符的个数。示例用法如下:
#include<iostream>
#include<cstring>
intmain(){
constchar*str="Hello,World!";
size_tlength=strlen(str);
std::cout<<"Lengthofthestring:"<<length<<std::endl;
return0;
}
上述代码会输出字符串"Hello,World!"的长度,即13。
版权声明
本文仅代表作者观点,不代表博信信息网立场。