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

std::vector::max_size

size_type max_size() const;

返回容器由于系统或库实现限制而能够容纳的最大元素数,即std::distance(begin(), end())最大的集装箱。

参数

%280%29

返回值

最大元素数。

例外

(none)

(until C++11)

noexcept specification: noexcept

(since C++11)

复杂性

常量。

注记

此值通常反映容器大小的理论限制。在运行时,容器的大小可能被限制为小于max_size()可用内存的数量。

二次

代码语言:javascript
复制
#include <iostream>
#include <vector>
 
int main()
{
    std::vector<char> s;
    std::cout << "Maximum size of a 'vector' is " << s.max_size() << "\n";
}

二次

可能的产出:

二次

代码语言:javascript
复制
Maximum size of a 'vector' is 18446744073709551615

二次

另见

size

returns the number of elements (public member function)

capacity

returns the number of elements that can be held in currently allocated storage (public member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券