当前位置:网站首页>Std:: vector copy, append, nested access
Std:: vector copy, append, nested access
2022-07-29 10:57:00 【Miaowei】
stl List of articles
List of articles
Preface
std::vector Copy 、 Additional 、 Nested access
One 、 Copy
1. Using the copy assignment operator ( Deep copy ), Note that the left value will be cleared first , Then copy the right value to the left value
vector<int> rightArray{
8,3,5,2,6,4,1};
vector<int> leftArray{
9,1,2,3};
leftArray= rightArray;
Before copying :
After the assignment :
The original :leftArray Medium 9,1,2,3 It was emptied first , Then put the rightArray{ 8,3,5,2,6,4,1 }; Copied to the leftArray in
2. Make use of copy construction ( Deep copy )
vector<int> rightArray{
8,3,5,2,6,4,1 };
vector<int> leftArray(rightArray);
3. utilize swap() function ( Two exchanges vector)
leftArray and rightArray The original value will be cleared first , Then exchange values with each other
Exchange before
After exchanging
4. utilize assign() function ( Empty and copy deeply )
rightArray Will be emptied first. , Then take it. leftArray Copied to the rightArray
Before assignment
After the assignment :
4. Memory copy ( Deep copy )
memmove front
memmove after :rightArray Empty the whole thing , Including redundant {4,1 Will also be emptied ,leftArray{ 9,0,7,7,0 }; Will retain
边栏推荐
- VMware: use commands to update or upgrade VMware esxi hosts
- Detailed arrangement of JVM knowledge points (long text warning)
- 大伟 GBase8s游标稳定性读ESQL测试用例
- 1.MySQL数据库的介绍
- Sunwenlong, Secretary General of the open atom open source foundation, worked together to expand open source
- 使用tidymodels搞定二分类logistic模型
- Meituan and hungry were interviewed by Hangzhou supervisors to implement the responsibility of food safety management and prohibit malicious competition
- 为什么应该在开发环境中使用 Kubernetes
- 带你浅聊一下PHP搭建的电商商城系统
- Kunlunbase instruction manual (I) quick installation manual
猜你喜欢
Kunlunbase instruction manual (II) best practices for peer-to-peer deployment
一键搭建博客:如何使用WordPress插件搭建专属博客
幸运抽奖系统带后台源码
Basic construction of QT project
StarRocks 技术内幕:实时更新与极速查询如何兼得
如何使用 grep 跨多行查找模式匹配
PaddleLite 编译以及代码跑通复盘
AI model risk assessment Part 2: core content
Analysis of QT basic engineering
QT基本工程的解析
随机推荐
Applied practical skills of deep reinforcement learning
Package Delivery(贪心)
从零开始Blazor Server(3)--添加cookie授权
Analysis of QT basic engineering
How to synchronize when the primary and sub warehouses are modified?
『面试知识集锦100篇』1.面试技巧篇丨HR的小心思,你真的懂吗?
如何开始为您的 Kubernetes 应用程序编写 Helm 图表
VMware: use commands to update or upgrade VMware esxi hosts
Conference OA project - my approval
一文搞懂什么是二叉树(二叉树的种类、遍历方式、定义)
『知识集锦』一文搞懂mysql索引!!(建议收藏)
2.安装MySQL
开源峰会抢先看 | 7月29日分论坛&活动议程速览
Exclusive interview | Cheng Li, chief technology officer of Alibaba: cloud + open source together form a credible foundation for the digital world
leetcode-位运算
The heavy | open atomic school source activity was officially launched
sql join中on条件后接and和where
Hutool日期时间
IPV6基础
Watch the open source summit first | quick view of the sub Forum & Activity agenda on July 29