STL中的resize函数与capacity函数
来源:互联网 发布:iphone6网络 ios10 编辑:程序博客网 时间:2024/06/06 17:47
//下面这个程序很有意思,看看发现到第二次的时候svec里面不是1000个元素,这实际上是resize()函数在作怪!但是最后一步中的capacity如何为3000多的我自己也不太清//楚,如果有知道的可以给我留言:#include <vector>#include <string>#include <iostream>using namespace std;int main(){ vector<string> svec; svec.reserve(1024); int n=0; while(n++<256) { string tmp; svec.push_back(tmp); } cout<<"the last size : "<<svec.size()<<endl; cout<<"the capasity before resize : "<<svec.capacity()<<endl; svec.resize(svec.size()+svec.size()/2); cout<<"after resize of the svec:"<<svec.size()<<endl; cout<<"after read words, capacity : "<<svec.capacity()<<endl; cout<<endl; while(n++<1000) { string tmp; svec.push_back(tmp); } cout<<"n= "<<n<<endl; cout<<"the last size : "<<svec.size()<<endl; cout<<"the capasity before resize : "<<svec.capacity()<<endl; svec.resize(svec.size()+svec.size()/2); cout<<"after resize of the svec:"<<svec.size()<<endl; cout<<"after read words, capacity : "<<svec.capacity()<<endl; cout<<endl; while(n++<1048) { string tmp; svec.push_back(tmp); } cout<<"the last size : "<<svec.size()<<endl; cout<<"the capasity before resize : "<<svec.capacity()<<endl; svec.resize(svec.size()+svec.size()/2); cout<<"after resize of the svec:"<<svec.size()<<endl; cout<<"after read words, capacity : "<<svec.capacity()<<endl; //最后这一步的capacity()为什么不是4096??? }
- STL中的resize函数与capacity函数
- STL中容器的几个容易混淆的成员函数-size, capacity, resize, reserve
- STL中容器的几个容易混淆的成员函数-size, capacity, resize, reserve
- STL中容器的几个容易混淆的成员函数-size, capacity, resize, reserve
- STL之resize()函数
- C++容器中 size(), capacity, reserve() ,resize() 函数讲解
- C++容器中 size(), capacity, reserve() ,resize() 函数
- C++容器中 size(), capacity, reserve() ,resize() 函数讲解
- opencv中的图像resize函数
- OpenCV中的Resize函数和Reshape函数
- vector中的resize()函数 VS reserve()函数
- resize函数
- resize()函数
- 容器中reserve()函数与resize()函数
- STL容器的reserve()函数和resize()函数解析
- STL中vector的capacity、size、reserve、resize
- 关于vector中的assign和resize函数
- STL中的capacity和size
- uboot 环境变量例子
- 在Android上使用ZXing识别条码/二维码
- Isgl3d获取视屏点击位置
- Linux中的静态库共享库
- 解析:Program received signal: “EXC_BAD_ACCESS"
- STL中的resize函数与capacity函数
- Unity界面插件NGUI基础教程
- wifi 的几种加密方式
- 远程服务器返回错误: (401) 未经授权 解决方案2007-04-06 13:441、错误号401.1
- vi 常用命令行
- groovy的动态性
- 22 个免费的图表、流程图工具
- XCode4.2如何取消自动释放
- Lua标准库: table函数, 数学函数, 字符串函数/格式化/配对, WoW新增函数, 函数别名