std::strlen - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::strlen

From cppreference.com
< cpp‎ | string‎ | byte

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

Returns the length of the given null-terminated byte string, that is, the number of characters that precede the terminating null character.

### [edit] Parameters

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

### [edit] Return value

The length of the null-terminated string `str`.

### [edit] Example

Run this code

    #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';
    }

Output:

    without null character: 45
    with null character: 46

### [edit] See also

C documentation for strlen

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/string/byte/strlen&oldid=72217"