std::strlen
| Defined in header <cstring>
|
||
| std::size_t strlen( const char* 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.
Contents |
[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] Possible implementation
std::size_t strlen(const char* start) { const char* end = start; while(*end++ != 0); return end - start - 1; } |
[edit] Example
#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
| returns the length of a wide string (function) | |
| returns the number of bytes in the next multibyte character (function) | |
| C documentation for strlen
| |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
