vector 的使用

size/resize  以及 capacity/reserve 之间的区别

size 取得 vector 中元素的个数,resize 重新分配空间,并且将分配的空间初始化为0,

capacity : return number of elements for while memory has been allocated

reserve:Allocates elements for vector to ensure a minimum size,preserving its contents if the new size is larger than existing size,buf not initializationvalue for zero.

所以我们只可以使用operator[] 或 at() 去修改实在存在于容器中的元素.

 

1.尽量做到const 正确性

2。尽量使用 != 而不是使用 < 来比较两个迭代器

3。尽量使用前缀的 -- 与 ++,因为后缀的++ 与-- 使用到临时变量

4。避免无谓的求值

5。尽量使用"/n"而不是endl. 使用endl 会迫使输出流刷新其缓冲区

6。尽量使用标准库中的copy 与for_each,而不是自己手写循环

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值