#include <iomanip> #include <iostream> #include <vector> int main() { int sz = 100; std::vector<int> v; auto cap = v.capacity(); std::cout << "Initial size: " << v.size() << ", capacity: " << cap << '\n'; std::cout << "\nDemonstrate the capacity's growth policy...
#include<iostream>#include<vector>voidprintCapLen(conststd::vector<int>&v){std::cout<<"Capacity: "<<v.capacity()<<" Length:"<<v.size()<<'\n';}intmain(){std::vector v{0,1,2};// length is initially 3printCapLen(v);for(autoi:v)std::cout<<i<<' ';std::cout<<'\n';v.r...
std::vector<T,Allocator>::empty std::vector<T,Allocator>::size std::vector<T,Allocator>::max_size std::vector<T,Allocator>::reserve std::vector<T,Allocator>::capacity std::vector<T,Allocator>::shrink_to_fit std::vector<T,Allocator>::clear std::vector<T,Allocator>::insert std::vecto...
#include<iostream>#include<vector>voidprintCapLen(conststd::vector<int>&v){std::cout<<"Capacity: "<<v.capacity()<<" Length:"<<v.size()<<'\n';}intmain(){std::vector v{0,1,2};// length is initially 3printCapLen(v);for(autoi:v)std::cout<<i<<' ';std::cout<<'\n';v.r...
std::vector<T,Allocator>::capacityC++ 容器库 std::vector size_type capacity() const; (C++11 前) size_type capacity() const noexcept; (C++11 起) 返回容器当前已为之分配空间的元素数。 参数(无) 返回值当前分配存储的容量。 复杂度常数。