当前位置:网站首页>39.【vector动态数组定义及初始化】
39.【vector动态数组定义及初始化】
2022-07-30 06:29:00 【李在奋斗……】

【vector数组的定义】
vector<数据类型> 函数名
#include <vector>
using namespace std;
int main()
{
int a[10]; //正常定义
vector<int> str_a; //vector 定义
char b[10];
vector<char> str_b;
float c[10];
vector<float> str_c;
}

【vector数组的初始化】
1.vector<数据类型> 函数名; 初始化为空
2.vector<数据类型> 函数名(a,b).定义a个空间,都初始化为b。
3.vector<数据类型> 函数名1=函数名2. 把动态数组2复制给动态数组1。
4.vector<数据类型> 函数名1(函数名2.begin(),函数名2.end()). 把动态数组2复制给动态数组1。
5.vector<数据类型> 函数名(a,a+sizeof(a)/
sizeof(数据类型)),把普通数组a复制给动态数组。
#include <vector>
using namespace std;
int main()
{
int a[5] = {1,2,3,4,5};
vector<int> str_a; //初始化为空
vector<int> str_a1(4, 88); // 定义四个元素,每个元素的值为88;
vector<int> str_a2 = str_a1; //把a1的值复制给a2;
vector<int> str_a3(str_a1.begin(), str_a1.end()); //把a1的值复制给a2;
vector<int> str_a4(a, a + sizeof(a)/sizeof(int)); //复制正常数组的初始化
return 0;
}

边栏推荐
- 一段神奇的没有主方法的代码
- sizeof
- 【雷达目标检测】恒定阈值法和恒虚警(CFAR)法及代码实现
- Derivative Operations on Vectors and Derivative Operations on Vector Cross and Dot Products
- MySQL off-topic [ORM thought analysis]
- Delphi仿制Web的导航
- Go 使用 freecache 缓存
- Get all interface paths and names in the controller
- 02 多线程与高并发 - synchronized 解析
- Go: use gorm query record
猜你喜欢
随机推荐
2020 ACM | MoFlow: An Invertible Flow Model for Generating Molecular Graphs
go : 使用gorm修改数据
General Lei's personal blog to see
K-Net:Towards Unified Image Segmentation,基于动态内核的通用分割网络,(NMS-free and Box-free),从语义/实例分割到全景分割。
muduo库学习记录(一)
潜心打磨,主动求变——这群技术排头兵,如何做好底层开发这件事?
redis常用指令
ArrayList
入选“十大硬核科技”,详解可信密态计算(TECC)技术点
动态规划专栏
Keil compile size and storage instructions
【COCI 2020/2021 Round #2 D】Magneti(DP)
包含min函数的栈(js)
C语言自定义类型详解
【防作弊】Unity防本地调时间作弊
IDEA搜索插件无结果一直转圈圈的解决办法
Keil软件中map文件解析
C# 获取系统已安装的.NET版本
Handler消息机制-Native层
Vue2进阶篇-编程式路由导航、缓存路由组件、路由的激活与失活




![[GO Language Basics] 1. Why do I want to learn Golang and get started with GO language](/img/ac/80ab67505f7df52d92a206bc3dd50e.png)



