Instantiated member variants

length

Template: std::char_traits<T>

Specializations:
  • char
  • wchar_t
  • char8_t
  • char16_t
  • char32_t

Returns the length of the character sequence pointed to by s, that is, the position of the terminating null character (char_type()).

# Declarations

static std::size_t length( const char_type* s );

(constexpr since C++17)

# Parameters

# Return value

The length of character sequence pointed to by s.

# Example

#include <iomanip>
#include <iostream>
#include <string>
 
void print(const char* str)
{
    std::cout << std::quoted(str) << " has length = "
              << std::char_traits<char>::length(str) << '\n';
}
 
int main()
{
    print("foo");
 
    std::string s{"booo"};
    print(s.c_str());
}