max_size函数
语法:
1 |
size_type max_size() const |
max_size() 返回Vector所能容纳元素的最大数量(上限)
源代码
1 2 3 |
/** Returns the size() of the largest possible %vector. */ size_type max_size() const { return size_type(-1) / sizeof(value_type); } |
测试代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
// 梁笔记 // https://zouzhongliang.com #include <iostream> #include <vector> using namespace std; int main() { vector<int> v1; vector<int> v2(10, 2); v1.push_back(1); v1.push_back(2); v1.push_back(3); v1.push_back(4); v1.push_back(5); cout<<v1.size()<<endl; cout<<v1.max_size()<<endl; } |
测试结果:
1 2 |
5 1073741823 |