std::char_traits::length
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) |
所指向的字符序列的长度。s
,即终止空字符%28的位置。CharT()
29%。
参数
s | - | pointer to a character sequence to return length of |
---|
返回值
所指字符序列的长度s
...
例外
%280%29
复杂性
线性的。
例
二次
#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());
}
二次
产出:
二次
string 'foo' length = 3
string 'booo' length = 4
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com