2.vector数组
- 创建vector数组
vector<int> myint{ ,,,, }; - 尾部插入
for (int i = ; i < ; i++)
{
myint.push_back(i); } - 读取头部和尾部
cout << myint.front() << endl;
cout << myint.back() << endl; - 动态调整大小
myint.resize();//动态调整大小
- 设置只有六个数据但是缓冲区有90
myint.resize(, );//设置只有六个数据,但是缓冲有90
- 正向读取
for (auto ib = myint.begin(), ie = myint.end(); ib != ie; ib++)
{
cout << *ib << endl;
} - 逆向读取
for (auto rb = myint.rbegin(), re = myint.rend(); rb != re; rb++)
{
cout << *rb << endl;
} - 读取
for (int i = ; i < myint.size(); i++)
{
cout << myint[i] << endl;
} for (auto i : myint)
{
cout << i << endl;
} - 重新初始化
myint.assign(, );
- 根据位置插入
auto it = myint.begin() + ;
myint.insert(it, );//根据位置插入 - 插入一个数组
int a[] = { ,,,, };
myint.insert(it, a, a + );//插入一个数组 - 插入一个vector
vector<int> myintX = { ,, };
//批量插入
myint.insert(it, myintX.begin(), myintX.end()); - 删除和批量删除
myint.erase(it);
myint.erase(myint.begin(), myint.begin() + );//批量删除 - 调用分配器使用自己分配的内存
//调用分配器
vector<int> mymem;
int *p = mymem.get_allocator().allocate();//获取分配器分配内存
for (int i = ; i < ; i++)
{
cout << (p[i] = i) << endl;
}
myint.get_allocator().deallocate(p, );//释放内存 - vector嵌套
//vector嵌套
vector<int> myint1{ ,, };
vector<int> myint2{ ,, };
vector<int> myint3{ ,, };
vector<vector<int>> myallint{ myint1,myint2,myint3 };
for (auto i : myallint)
{
for (auto j : i)
{
cout << j << endl;
}
}
2.vector数组的更多相关文章
- c++中的array数组和vector数组
我觉得实验一下会记得比较牢,话不多直接上代码. 下面是array数组,感觉用的不多. //cpp 风格数组 array #include <iostream> #include <a ...
- c++ vector数组的定义使用
/* *********************************************** Author :guanjun Created Time :2017/3/18 13:32:52 ...
- c++ vector数组的使用
介绍: 首先我们要明白以下几点: 1.vector数组是一个能存放任意数据类型(类,结构,普通变量类型等)的动态数组!,在数据结构中就相当于顺序储存的线性表,寻找元素非常快,但是插入元素的时间却很大( ...
- vector数组的相关知识
Vector 类实现了一个动态数组.和 ArrayList 很相似,但是两者是不同的: Vector 是同步访问的. Vector 包含了许多传统的方法,这些方法不属于集合框架. Vector 主要用 ...
- 动态创建二维vector数组 C和C++ 及指针与引用的区别
二维vectorvector<vector <int> > ivec(m ,vector<int>(n)); //m*n的二维vector 动态创建m*n的二 ...
- ArrayList , Vector 数组集合
ArrayList 的一些认识: 非线程安全的动态数组(Array升级版),支持动态扩容 实现 List 接口.底层使用数组保存所有元素,其操作基本上是对数组的操作,允许null值 实现了 Randm ...
- UVa——1593Alignment of Code(string重定向+vector数组)
UVA - 1593 Alignment of Code Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
- C++ 中vector数组的使用
(1)头文件:#include<vector>.(2)创建vector对象: vector < 类型 > 名字; 例:vector<int> vec;(3) ...
- 妙用Pixel bender执行复杂运算/普通数据运算 传递Vector数组
最近发现pixel bender有两个特殊点: 1.Input Image4,不单单可以用BitmapData来初始化,也可以用Vector.<Number>初始化. 2.ShaderJo ...
随机推荐
- Spring MVC -- UEditor 编辑器整合 上传图片至外部文件夹(非项目文件夹)
上传图片到外部储存,回显图片 下载全部UEditor资源源码 config.json配置 config.json中添加如下属性 (一定要添加此属性): "physicsPath": ...
- codeforces 589A Email Aliases(map)
Description Polycarp has quite recently learned about email aliases. Of course, he used to suspect t ...
- url传递中文的解决方案总结
File文件控件,选中文件(图片,flash,视频)即立即预览显示 .Net刷新页面的几种方式 Attributes.Add用途与用法(C#) url传递中文的解决方案总结 byte[] bytes ...
- SqlCommand的四大方法
SqlCommand类的方法 ---->>>1.ExecuteNonQuery(); 它的返回值类型为int型.多用于执行增加,删除,修改数据,返回受影响的行数.当select操作时 ...
- 【Docker自定制镜像之Dockerfile】
镜像的定制,就是定制每一层所添加的配置.文件,如果可以把每一层修改.安装.构建.操作的命令都写入到一个脚本中,用脚本来构建.定制镜像,这个脚本就是Dockerfile Dockerfile是一个文本文 ...
- Python基础班培训视频课程
课程目录:│ ├─第01天视频│ │ 01-课程介绍.avi│ │ 02-什么是操作系统.avi│ │ 03-生活中的操作系统.avi│ │ 04-操 ...
- Django and Scrapy 用法图片
- Windows操作系统下将Redis安装为服务
安装服务: E:/Redis/Redis-x64-3.2.100/redis-server.exe --service-install E:/Redis/Redis-x64-3.2.100/redis ...
- 洛谷——P1518 两只塔姆沃斯牛 The Tamworth Two
https://www.luogu.org/problem/show?pid=1518 题目背景 题目描述 两只牛逃跑到了森林里.农夫John开始用他的专家技术追捕这两头牛.你的任务是模拟他们的行为( ...
- VS添加程序集
项目->添加->引用->程序集 可在项目的引用目录中,查看引用的程序集