使用向量的元素 [英] using the elements of a vector
本文介绍了使用向量的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
已更新:
抱歉,我认为我的问题不够清楚,因此我将问题更新为:
我有一个向量,它有5个元素
现在我该如何使用它的第二个元素,我的意思是在数组中我们可以通过[]使用它,例如:myarray [1]但在向量中我不能使用[],我该怎么办?
在此先感谢
解决方案
使用std :: list或std:vector(向量是一个数组).标准模板库是文章(而不是论坛回复)中最好涵盖的主题.
STL 101 A部分-矢量 [ at "功能
UPDATED:
sorry,i think my question wasnt clear enough so i updated my question to this:
i have a vector and it has 5 elements
now how can i use for example second element of it,i mean in array we can use it by [] for example : myarray[1] but in vector i cant use [],what should i do?
thanks in advance
解决方案
Use std::list or std:vector ( a vector is an array ). The standard template library is a subject best covered in articles, not forum replies.
STL 101 Part A - Vector[^]
If you''re using this within a for()
loop, then odds are you do know the size. Remember that you should only use a dynamic container when you need it, otherwise it will tend to make your program quite a bit slower (depending on which container you choose, the amount will vary) since dynamic memory allocations are quite costly in time.
Use "at" function of of vector class
这篇关于使用向量的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文