From cppreference.com
std::size_tstrlen(constchar*str);Returns the length of the given byte string, that is, the number of characters in a character array whose first element is pointed to by str up to and not including the first null character. The behavior is undefined if there is no null character in the character array pointed to by str.
Parameters
str - pointer to the null-terminated byte string to be examined Return value
The length of the null-terminated string str.
Possible implementation
std::size_tstrlen(constchar*start){// NB: start is not checked for nullptr!constchar*end=start;while(*end!='\0')++end;returnend-start;}Example
Run this code
#include<cstring>#include<iostream>intmain(){constcharstr[]="dog cat\0mouse";std::cout<<"without null character: "<<std::strlen(str)<<'\n'<<"with null character: "<<sizeofstr<<'\n';}Output:
without null character: 7 with null character: 14 See also