当前位置:网站首页>STL resize capacity rule set
STL resize capacity rule set
2022-07-22 17:31:00 【joker_ 0030】
1、
#include <iostream>
#include<vector>
#include<list>
using namespace std;
void fun1()
{
string db(5, 'a');
cout << db.capacity() << endl;
db.resize(3);// law : Reset the number of elements , If the number of elements is less than the default capacity ( Default capacity is 15, Reset the number of elements to 3), Then the capacity remains the same ; If the number of reset elements is greater than the capacity, the capacity will increase , If the set capacity is 6, If the number of elements is reset to 17, Then the capacity is 31.
cout << db << endl;
cout << db.capacity() << endl;
db.resize(17);//15 31 47 Regular increase :15 16 16
cout << db.capacity() << endl;
vector<int> db2(6);
cout << db2.capacity() << endl;
db2.resize(3);// Reset the number of elements , Equal to capacity ( For example, set the capacity to 6, Reset the number of elements to 3), Then the capacity remains the same ; If the number of reset elements is greater than the capacity, the capacity will increase , If the set capacity is 6, If the number of elements is reset to 7, Then the capacity is 6+6/2=9.
cout << db2.capacity() << endl;
db2.resize(7);
cout << db2.capacity() << endl;
list<int> db3(5);
cout << db3.size() << endl;
db3.resize(3);// Reset the number of elements , Capacity ( For example, set the capacity to 5, Reset the number of elements to 3), Then the capacity is 3.
cout << db3.size() << endl;
db3.resize(7);
cout << db3.size() << endl;
}
int main()
{
fun1();
system("pause");
return 0;
}
边栏推荐
- 微信营销策略,微信营销的优势是什么?
- unity PostProcess 屏幕后处理
- mysql约束之_非空约束
- Domain Driven Design
- 【矩阵乘法】外部矩阵乘法
- Go语言学习日记【三十一】golang与pgsql交互
- ACL and net
- Understand five popular NFT delivery methods and their advantages and disadvantages
- [pictures and texts] detailed tutorial of online one click reinstallation of win7 system
- 一个注解实现方法返回数据写入缓存(切面、Redis实现)
猜你喜欢
Win11终端管理员打不开解决方法
Network Security Learning (Qianfeng network security notes) 5 -- NTFS security permissions
并发程序的噩梦——数据竞争
Go language learning diary [XXXI] interaction between golang and PgSQL
pytorch
NFS shared storage service
Openeuler is ambitious, open source huizhichuang future | 2022 open atom global open source summit openeuler sub forum is about to open
【LeetCode】814. 二叉树剪枝
[pictures and texts] detailed tutorial of online one click reinstallation of win7 system
广度优先遍历(Breath First Search)
随机推荐
JS的DOM操作——事件代理
利用二分法查找数组的元素
Li Hongyi machine learning 2020--p20 & 21 RNN
Spark advanced features, 220720,
Win11闪白屏无法控制如何解决?
How to implement Apache's built-in AB stress testing tool
重装Win11系统如何在线一键进行?
PostgreSQL determines whether it is empty coalesce
2022年暑假ACM热身练习3(部分题目总结)
Reading papers [6] autoassembly: learning augmentation strategies from data
MySQL constraint_ Self growth constraint_ auto_ increment
mysql约束之_唯一约束
354. Russian Doll envelope problem
Openeuler is ambitious, open source huizhichuang future | 2022 open atom global open source summit openeuler sub forum is about to open
牛客网 替换空格
分布式计算框架Map/Reduce
pytorch
Castor realizes high-throughput analysis of large-scale cloud assembly through polygonica 3D engine, and hoops exchange helps it read CAD data files
微信营销策略,微信营销的优势是什么?
《PyTorch深度学习实践》-B站 刘二大人-day2