首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_string::size

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等多字节编码,则这些对象与字符不同。

二次

代码语言:javascript
复制
#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)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券