当前位置:网站首页>STL Vector capacity
STL Vector capacity
2022-07-20 12:41:00 【joker_ 0030】
1、
#include <vector>
#include <iostream>
using namespace std;
void STLCapacity()
{
vector<int> db(4);
cout << db.empty() << endl;// Determine whether the object has elements , No element returns 1, Element returned 0.
db.resize(3);// Reset the number of elements , The capacity size remains the same .
db.reserve(10);//reserve(10) take db Capacity becomes 10, Only increase, not decrease 10 Be greater than db Its capacity .
cout << db.size() << endl;// Number of elements .
cout << db.capacity() << endl;//vector Capacity function of capacity() What you get is the size of the capacity .
//vector<int> db1(5);// Object initialization is a few , The capacity is a few .
//cout << db1.capacity() << endl;
VS When the capacity in the version is insufficient , Add half of the existing capacity ,5+5/2==7. VC When the capacity in the version is insufficient , Double the existing capacity , namely 5*2.
//db1.push_back(1);//6( data )==5+1>5( Capacity ), So add capacity , The capacity size becomes :5+5/2==7.
//cout << db1.capacity() << endl;
//db1.push_back(1);//6+1( data )=7( Capacity ); The capacity can accommodate 7 individual , So the size remains the same .
//db1.push_back(1);//8( data )==7+1>7( Capacity ), So add capacity , The capacity size becomes :7+7/2==10.
//cout << db1.capacity() << endl;
}
int main()
{
STLCapacity();
system("pause");
return 0;
}
// Be careful :reserve() And capacity() Function reallocates capacity , Iterative failure .
边栏推荐
- [solution] the Monaco editor in leetcode cannot be loaded
- vulnhub Monitoring: 1
- Solution: the configuration and path are completely correct, but the gateway cannot be accessed
- Virtual exhibition combines AI digital people to help enterprises solve the current dilemma
- [HDU 6095] Rikka with Competition
- Flask request data and get response
- Rancher installation, deployment and basic use
- Style transfer --- detailed explanation of stargan code and interpretation and translation of papers
- [Hongke news] Hongke electronics officially established a partnership with Weka
- Opencv (12): cv:: rectangle learning and code demonstration, using OpenCV to draw rectangles / rectangular boxes
猜你喜欢
收集表单数据 v-model
Xiaobai learns MySQL - generated columns function
Understand the MySQL architecture design in one article, and don't worry about the interviewer asking too much
黑客破解赌博网站漏洞每月“薅羊毛”10万
【深度学习】pytorch使用tensorboard可视化实验数据
LED light of 51 single chip microcomputer
Why psp22 is important to Polkadot ecosystem
Use of pH meter, conductivity meter and chlorophyll fluorescence meter
Reflective Decoding: Beyond Unidirectional Generation with Off-the-Shelf Languag
Understand the trading volume and turnover rate in one article
随机推荐
Weekly recommended short videos: put forward higher requirements for the elastic computing power of cloud computing
JUC_synchronized关键字详解
[nightsafe AI] create the NFT digital art collection you want in one minute
模板与泛型编程之退化技术
Essential certificate for product manager!
notepad++如何取消空行
[sklearn error reporting solution] undefined metricwarning: precision is ill defined and being set to 0.0
Rancher安装部署及基本使用
Data analysis children's shoes can't be missed | operational risk control business analysis report
科技竞争力评估体系研究与实践
新闻速递 | 恭喜肖晓容工程师获得Domo专业认证!
微服务--熔断和限流
IDEA注释模板配置
[solution] the Monaco editor in leetcode cannot be loaded
Three leetcode questions corresponding to the basic knowledge of linked list (2)
c语言远程连接mysql成功,无法插入数据
LED light of 51 single chip microcomputer
Hcia-r & s self use notes (11) VRP file system, system management
出于对员工人身安全的担忧 星巴克未来可能关闭更多美国门店
【深度学习】pytorch使用tensorboard可视化实验数据