容器问题
来源:百度知道 编辑:UC知道 时间:2024/09/21 08:29:15
容器的
max_size
和
capacity
有什么区别
max_size
和
capacity
有什么区别
#include <iostream>
#include <vector>
using namespace std;
void showsize(const vector<int>& a);
int main()
{
vector<int> test(10,1);//init 1*10
cout<<"first:\n";
showsize(test);
cout<<"then:\n";
test.push_back(1); //put "1"
showsize(test);
cout<<"last test:\n";
for(int i=0;i<=10;i++)
test.push_back(1);
showsize(test);
return 0;
}
void showsize(const vector<int>& test){
cout<<"maxsize: "<<test.max_size()<<endl;
cout<<"siez: "<<test.size()<<endl;
cout<<"capacity: "<<test.capacity()<<endl;