public static member function
static size_t length (const char_type* s);
Get length of null-terminated string
Returns the length of the null-terminated character sequence s.
The behavior implemented by all character traits types shall be to return the position of the first character for which member eq returns false when compared against charT().
This function is equivalent to strlen (for char) and wcslen (for wchar_t).
- Pointer to a null-terminated character sequence.
Member type char_type is the character type (i.e., the class template parameter in char_traits).
Returns the length of s.
size_t is an unsigned integral type.
#include <iostream> // std::cout
#include <string> // std::char_traits
int main ()
const char * foo = "String literal";
std::cout << "foo has a length of ";
std::cout << std::char_traits<char>::length(foo);
std::cout << " characters.\n";
foo has a length of 14 characters.
Linear in the returned value.
If s points a null-terminated character sequence, this member function never throws exceptions (no-throw guarantee) in any of the standard specializations.
Otherwise, it causes undefined behavior.
- End-of-File character ( public static member function
- Get string length (function
- Get wide string length (function