矢量会动态增长 [英] will vector grow dynamically

查看:103
本文介绍了矢量会动态增长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

stl vector会自动动态增长



mfc中的CArray会不会?因为vector有SetAtGrow

stl vector will grow dynamically by it self automatically

CArray in mfc will not ? as vector has SetAtGrow

推荐答案

是和否。



如果你这样做:

Yes and No.

If you do:
std::vector<int> V;
V[7] = 123;
</int>

它会崩溃。好吧,它会给你很好的调试错误。

但是你可以这样做:

it will crash. Well, it will give you nice errors in debug.
But you can do:

V.push_back (1234);



和V将适当增长。



这与CArray非常相似。



我希望有帮助,



Iain。


and V will grow appropriately.

That's pretty similar with CArray as well.

I hope that helps,

Iain.


文档 [ ^ ]:

支持类似于C数组的数组,但可以根据需要动态地减少和增长。

The very first sentence in the documentation[^]:

Supports arrays that are like C arrays, but can dynamically reduce and grow as necessary.


这篇关于矢量会动态增长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆