How to Use Arrays and Vectors
2024-09-08 18:53:06
array it needs a constant value
const int seq_size = 18;
int pell_seql[seql_size];
//defined a constant value: seq_size = 18
As vector,First, we need to include Head file of vector: #include<vector>
vector is a template,So we need to add curly braces <Type>
Size don't need to be a Constant value here
#include<vector>
vector<int> pell_seql(seq_size);//Attention! Size don't need to be a constant value here
whether array or vector,we can appoint Location,by []
pell_seql[0] = 1;//The first element is 1
pell_seql[1] = 2;//The second element is 2
initialization
array
int elem_seq[seql_size] = {,,,};//cant over size
vector
First Merhod(Troublesome)
vector<int>elem_seq(seql_size);
elem_seq[0] = 1;
elem_seq[1] = 2;
............etc
The second Method
int elem_vals[seq_size] = {1,2,3,4,5,6,7,8,9};
vector<int>elem_seq(elem_vals,elem_vals + seq_size)//the two values here refer to location,They identify Initialized element range
There is a difference between Array
and Vector
: Vector know its size
最新文章
- MFC的定时器OnTimer
- 反射,System.Type类
- Spring.Net实现IOC和DI
- Windows Server 2012 GUI与Core的切换
- RGPJS 教程之八 创造场景
- java 对excel操作导入excel数据到数据库
- 【hbase】使用thrift with python 访问HBase
- AT-FragmentPagerAdapter
- Android学习手记(3) Activity间传递数据
- 知识点1-3:MVC设计模式
- Mybatis第二篇【CRUD、分页】
- hdu 1052 Tian Ji -- The Horse Racing【田忌赛马】
- container and Injection
- python大法好——面向对象
- Java并发——线程中断学习
- 02-里氏替换原则(LSP)
- [原创] 浅谈ETL系统架构如何测试?
- Webpack 性能优化 (一)(使用别名做重定向)
- ubuntu(14.04) sphinx安装
- JAVA-JSP内置对象之application对象获得服务器版本