Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::char_traits::length(3)   C++ Standard Libary  std::char_traits::length(3)

NAME
       std::char_traits::length	- std::char_traits::length

Synopsis
	  static  std::size_t  length( const char_type*	s );		(until
       C++17)
	  static constexpr std::size_t length( const char_type*	s  );	(since
       C++17)

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

Parameters
	  s - pointer to a character sequence to return	length of

Return value
	  The length of	character sequence pointed to by s.

Exceptions
	  Throws nothing.

Complexity
	  Linear.

Example
       // Run this code

	#include <iostream>
	#include <iomanip>
	#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());
	}

Output:
	"foo" has length = 3
	"booo" has length = 4

http://cppreference.com		  2022.07.31	   std::char_traits::length(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::char_traits::length&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help