Localization library | |||||||||||||||||||||||||
Regular expressions library(C++11) | |||||||||||||||||||||||||
Formatting library(C++20) | |||||||||||||||||||||||||
Null-terminated sequence utilities | |||||||||||||||||||||||||
Byte strings | |||||||||||||||||||||||||
Multibyte strings | |||||||||||||||||||||||||
Wide strings | |||||||||||||||||||||||||
Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
Text encoding identifications | |||||||||||||||||||||||||
|
Functions | ||||||||||||||||||||||||||||||||||||
Character classification | ||||||||||||||||||||||||||||||||||||
Character manipulation | ||||||||||||||||||||||||||||||||||||
Conversions to numeric formats | ||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||
String manipulation | ||||||||||||||||||||||||||||||||||||
String examination | ||||||||||||||||||||||||||||||||||||
Character array functions | ||||||||||||||||||||||||||||||||||||
Miscellaneous | ||||||||||||||||||||||||||||||||||||
Defined in header <cstring> | ||
std::size_t strlen(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 bystr 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 bystr.
Contents |
str | - | pointer to the null-terminated byte string to be examined |
The length of the null-terminated stringstr.
std::size_t strlen(constchar* start){// NB: start is not checked for nullptr!constchar* end= start;while(*end!='\0')++end;return end- start;} |
#include <cstring>#include <iostream> int main(){constchar str[]="dog cat\0mouse"; std::cout<<"without null character: "<< std::strlen(str)<<'\n'<<"with null character: "<< sizeof str<<'\n';}
Output:
without null character: 7with null character: 14
returns the length of a wide string (function)[edit] | |
returns the number of bytes in the next multibyte character (function)[edit] | |
C documentation forstrlen |