Namespaces
Variants
Views
Actions

std::strlen

From cppreference.com
< cpp‎ | string‎ | byte
Revision as of 03:15, 10 December 2012 by Cubbi (Talk | contribs)

Defined in header <cstring>
std::size_t strlen( const char* str );

Returns the length of the given byte string.

Contents

Parameters

str - pointer to the null-terminated byte string to be examined

Return value

The length of the null-terminated string str.

Example

#include <cstring>
#include <iostream>
 
int main()
{
   const char str[] = "How many characters contains this string?";
 
   std::cout << "without null character: " << std::strlen(str) << '\n'
             << "with null character: " << sizeof(str) << '\n';
}

Output:

without null character: 41
with null character: 42

See also

C documentation for strlen