static std::size_t length( const char_type* s ); |
Returns the length of the character sequence pointed to by s
, that is, the position of the terminating null character (CharT()
).
s | - | pointer to a character sequence to return length of |
The length of character sequence pointed to by s
.
(none).
Linear.
#include <iostream> void print(const char* str) { std::cout << "string '" << str << "' "; std::cout << "length = " << std::char_traits<char>::length(str) << '\n'; } int main() { print("foo"); std::string s("booo"); print(s.c_str()); }
Output:
string 'foo' length = 3 string 'booo' length = 4
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/string/char_traits/length