原文:http://www.cnblogs.com/EE-NovRain/archive/2012/06/12/2546500.html
#include<iostream>
#include<vector>
using namespace std;
void main(){
vector<int> vec;
for(int i=1;i<=10;i++){
vec.push_back(i);
cout<<vec.size()<<" "<<vec.capacity()<<endl;
}
cout<<endl;
for(int i=1;i<=10;i++){
vec.pop_back();
cout<<vec.size()<<" "<<vec.capacity()<<endl;
}
cout<<endl;
if(true){
vector<int> temp;
vec.swap(temp); //通过swap()函数释放内存;
}
cout<<vec.size()<<" "<<vec.capacity()<<" "<<vec.max_size()<<endl;
}