std::basic_string::length
| size_type size() const; |  |  | 
|---|---|---|
| size_type length() const; |  |  | 
返回CharT字符串中的元素,即std::distance(begin(), end())...
参数
%280%29
返回值
的数目CharT字符串中的元素。
例外
| (none) | (until C++11) | 
|---|---|
| noexcept specification: noexcept | (since C++11) | 
复杂性
常量。
注记
为std::string,元素为字节%28类型的char%29对象,如果使用UTF-8等多字节编码,则这些对象与字符不同。
例
二次
#include <cassert>
#include <iterator>
#include <string>
 
int main()
{
    std::string s("Exemplar");
    assert(8 == s.size());
    assert(s.size() == s.length());
    assert(s.size() == static_cast<std::string::size_type>(
        std::distance(s.begin(), s.end())));
}二次
另见
| empty | checks whether the string is empty (public member function) | 
|---|---|
| max_size | returns the maximum number of characters (public member function) | 
 © cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

