std::strlen

Header: <cstring>

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.

# Declarations

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

# Parameters

# Return value

The length of the null-terminated string str.

# Example

#include <cstring>
#include <iostream>
 
int main()
{
    const char str[] = "dog cat\0mouse";
 
    std::cout << "without null character: " << std::strlen(str) << '\n'
              << "with null character: " << sizeof str << '\n';
}

# See also