定长容器
#include<iostream>#include<vector>#include <string>#include <list>using namespace std;int main(){list<string> v;v.assign(10,"tt");cout << v.size() << endl;v.push_back("a");cout << v.size() << endl;}1011分配了10个空间,但还是可以动态增加的,无论是list还是vector
#include<iostream>#include<vector>#include <string>#include <list>using namespace std;int main(){vector<string> v;v.assign(10,"tt");cout << v.size() << "," << v.capacity() << endl;v.push_back("11");//再增加一个后,capacity的值会根据编译器的实现而不同,书上是double(20)但vs2012则是15cout << v.size() << "," << v.capacity() << endl;v.shrink_to_fit();//去除多余的空间cout << v.size() << "," << v.capacity() << endl;}10,1011,1511,11