vector 与 array

vector

STL中的模板数组(在堆中分配内存空间,通过new delete管理内存)

使用包涵头文件#include <vector>

vector<ElmentTpye> a1(number);

  • //初始化5空间大小的数组
  • vector<int> a1(5);
  • int a = 5;
  • vector<int> b1(a);

vector 创建数组,大小可以是变量值;

array

c++11中新定义的数组方法(在栈中分配内存空间)

array<Element, number> a1;

  • //初始化5空间大小的数组
  • array<int , 5> a1;
  • number 必需是常量

原文地址:https://www.cnblogs.com/flowingwind/p/8449864.html

时间: 2024-08-28 15:11:13

vector 与 array的相关文章

Namespace, string, vector and array

1. Headers should not include using declaration Code inside headers ordinarily should not include using declarations. The reason is that the contents of a header are copied into the including program's text. If a header has a using declaration, then

vector and array

#include<iostream> #include<vector> #include<array> int main() { using namespace std; int SIZE; cin >> LEN; vector<int> ar(LEN); array<int,LEN> br ={1,2,3,4,5}; return 0; }; vector 类型直接初始化赋值会报错,但是array 可以直接初始化.

vector 和array的用法

模板类vector 模板: 1 vector<typename>vt(n_elem); 其中n_elem可以是整型常量,也可以是整形变量.如: 1 #include<vector> 2 ... 3 using namespace std; 4 vector<int>vi;//大小为0 5 int n; 6 cin>>n; 7 vector<double>vd(n); 模板类array(c++11) 1 array<typename,n_el

java中vector和array区别

java中vector和数组非常类似,两者之间也经常成对出现,下面是两者的比较: 1.数组:java arrays的元素个数不能下标越界,从很大程度上保证了java程序的安全性,但创建时必须指定数组的大小,并不能再改变. 2.vector:对比于array,当更多的元素被加入进来以至超出其容量时,vector的size会动态增长,而array容量是定死的.同时,vector在删除一些元素后,其所有下标大于被删除元素的元素都依次前移,并获得新下标比原来的小了).

vector list array deque

因此在实际使用时,如何选择这三个容器中哪一个,应根据你的需要而定,一般应遵循下面 的原则:   1.如果你需要高效的随即存取,而不在乎插入和删除的效率,使用vector   2.如果你需要大量的插入和删除,而不关心随即存取,则应使用list   3.如果你需要随即存取,而且关心两端数据的插入和删除,则应使用deque. MSDN: 1. Introduction The STL vector class is a template class of sequence containers tha

STL之vector,数组线性容器array,list容器,算法find,find_if,bind1st,仿函数

 1.STL(Standard Template Library,是用泛型技术来设计完成的实例)的概念与组成 Iterator(迭代器) Container(容器) Algorithm(算法) Adaptors(配接器) STL的六大组件分别是: 容器(Container) 算法(Algorithm) 迭代器(Iterator) 仿函数(Function object) 适配器(Adapter) 空间配置器(allocator):只能分配内存等 2.容器与算法 案例如下: #include<

C++ vector二维数组

C++ 构建二维动态数组 int **p; p = new int*[10]; //注意,int*[10]表示一个有10个元素的指针数组 for (int i = 0; i < 10; ++i) { p[i] = new int[5]; } 这样就构成10*5的数组 vector二维数组 int i,j; vector<vector<int>> array(5); for (i = 0; i < array.size(); i++) array[i].resize(3)

对多维向量vector&lt;vector&lt;int&gt; &gt; vec进行操作

直接写作vector<vector<int> > vec在VC++6.0下编译不过改做:    typedef std::vector<int> ROW;    std::vector<ROW> vec;    vec[0][0] = 0;     vec[0][1] = 1; #include <iostream>#include <vector>using namespace std;int main(){     vector&

CUP对内存管理精华总(vector机制)

CPU对内存管理一: 内存:电容 操作系统:管理内存 CPU:处理数据. PC的CPU位数决定安装的操作系统位数,大了,浪费,小了无法安装操作系统 未来移动方向CPU与操作系统的最佳组合是Inter和微软 → 软件的沉淀 CPU对内存管理二: 内存4G用切割32位的方法划分为页表 页表和物理内存对应 优点:物理内存的保护和节省内存 一般认识的缺陷:可用内存4G,实际为少1M,一级页表 CPU对内存管理三: vector原理: 使用的内存,在页表中预留填写-1 -1提交后填写物理内存地址 使用完后