c ++ stl_通过分配另一个列表的所有元素来创建列表| C ++ STL

c ++ stl

There are two methods to implement it...

有两种方法可以实现它...

1 ) by assigning the existing list direct to the new list

1)通过直接将现有列表分配给新列表

    list<int> list2 = list1;

2 ) by using list::assign() function

2)通过使用list :: assign()函数

    list<int> list2;
list2.assign(list1.begin(), list1.end());

Example:

例:

In this example, we have a list list1 with 10 elements and we are creating another list list2, the elements of list2 will be assigning through the list1 by using list:assign() function, which is a library function of "list header". And, we are also creating a list list3 that is going to be assigned directly through the list1.

在这个例子中,我们有具有10个元素的列表list1的和我们正在创建另一个列表list2中 ,list2中的元素将通过使用列表中的列表1被分配:分配()函数,该函数是“列表头”的库函数。 并且,我们还创建了一个列表list3 ,它将直接通过list1进行分配。

Program:

程序:

#include <iostream>
#include <list>
using namespace std;
//function to display the list
void dispList(list<int> L)
{
//declaring iterator to the list
list<int>::iterator l_iter;
for (l_iter = L.begin(); l_iter != L.end(); l_iter++)
cout<< *l_iter<< " ";
cout<<endl;
}
int main()
{
//list1 declaration
list<int> list1 = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
//displaying list1
cout<<"Size of list1: "<<list1.size()<<endl;
cout<<"Elements of list1: ";
dispList(list1);
//declaring list2 and assigning the Elements
//of list1
list<int> list2;
list2.assign(list1.begin(), list1.end());
//displaying list2
cout<<"Size of list2: "<<list2.size()<<endl;
cout<<"Elements of list2: ";
dispList(list2);
//declaring list3 by assigning with list1
list<int> list3 = list1;
//displaying list3
cout<<"Size of list3: "<<list3.size()<<endl;
cout<<"Elements of list3: ";
dispList(list3);
return 0;
}

Output

输出量

Size of list1: 10
Elements of list1: 10 20 30 40 50 60 70 80 90 100
Size of list2: 10
Elements of list2: 10 20 30 40 50 60 70 80 90 100
Size of list3: 10
Elements of list3: 10 20 30 40 50 60 70 80 90 100  

翻译自: https://www.includehelp.com/stl/creating-a-list-by-assigning-the-all-elements-of-another-list.aspx

c ++ stl

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/380546.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

引用参数

• 默认情况下CLR规定所有方法的参数都按值传递的 • 参数类型分为:值类型参数和引用类型参数 • 参数传递方式:传值方式和传址方式 • Ref和Out的共同:传址传递 • Ref和Out的异同:ref修饰的参数必须在传递前对参数进行初始化;out反之,且必须在参数返回前进行初始化赋值 •在值…

jmp指令

功能&#xff1a; 无条件转移指令 jmp指令要给出两种信息&#xff1a; 转移的目标地址转移的距离&#xff08;段间转移、段内短转移、段内近转移&#xff09; 段内短转移&#xff1a; jmp short 标号&#xff09; assume cs:code code segmentstart:mov ax,0jmp short sad…

基于NIOS II的液晶显示设计——自定义图形库

基于NIOS II的液晶显示设计——自定义图形库 下面是我写的简单图形库 // graphics.h / #ifndef GRAPHICS_H_#define GRAPHICS_H_ #include"IO.h"#include"system.h"#include"alt_types.h"//定义SRAM缓存的基地址 #define SRAM_BASE LC…

在ASP.net中包含一个js文件

<script language"javascript" src"../../../Js/funBasic.js" type"text/javascript"></script><script language"javascript"><!--#INCLUDE VIRTUAL"*.js"--> </script>转载于:https://www.…

n个节点的二叉树n+1_使用C ++程序删除链接列表的M个节点后的N个节点

n个节点的二叉树n1Problem statement: 问题陈述&#xff1a; Given a Linked List, we have to delete N numbers of nodes after the M numbers of nodes. 给定一个链表&#xff0c;我们必须在M个节点之后删除N个节点。 Example: 例&#xff1a; Input: 1 → 2 → 3 → 4 →…

EAX、EBX、ECX、EDX

前面学习了8086的基本知识&#xff0c;今天正式开始学习win32平台的汇编 EAX&#xff1a;累加寄存器 32位&#xff0c;功能和8086中ax相同 mov eax,dword ptr [ebp-4] add eax,1 mov dword ptr [ebp-4],eaxEBX&#xff1a;基址寄存器 32位&#xff0c;功能和8086中bx相同 mov…

aspnet_Membership_GetUserByEmail////aspnet_Membership_GetUserByName

ALTERPROCEDUREdbo.aspnet_Membership_GetUserByEmail --通过邮箱获取用户名ApplicationNameNVARCHAR(256), EmailNVARCHAR(256)ASBEGINIF( EmailISNULL) SELECTu.UserName FROMdbo.aspnet_Applications a, dbo.aspnet_Users u, dbo.aspnet_Membership m …

php delete和truncate,TRUNCATE 删除表,无法回退。默认选择为整个表的内容,所以不能加条件。...

TRUNCATE 删除表&#xff0c;无法回退。默认选择为整个表的内容&#xff0c;所以不能加条件。DELETE 删除表&#xff0c;可以回退。可以带where 条件。建议使用delete。但是TRUNCATE 删除表数据比delete要快。使用TRUNCATE TABLE语句TRUNCATE TABLE语句提供了一种删除表中所有记…

【转】在Excel中如何输入平方米符号,输入立方米符号?

按住Alt键&#xff0c;在小键盘上输入178&#xff0c;然后放开Alt健&#xff0c;可以得到平方符号。 按住Alt键&#xff0c;在小键盘上输入179&#xff0c;然后放开Alt健&#xff0c;可以得到立方符号。转载于:https://www.cnblogs.com/temptation/archive/2011/04/25/2028587.…

dates.format_在SQL中使用DATES及其不同的内置函数NOW(),FORMAT()

dates.formatBasically, when we are working with dates, we need to be sure that the format of the date, we are trying to insert in the database is in format, and matches the format of the date column in the database. 基本上&#xff0c;当我们使用日期时&#…

砂.随笔.三

刚在整理电脑中的照片,把朋友们的照片都整进了"众生相",当点到他的照片时,迟疑了,没拉进去当剪切粘贴时,不知出了什么故障,"铛"地一声,"众生相"成了一空文件夹我不是一个容易觉得可惜的人,只是居然不禁窃喜适才没将他的照片放进去敲了敲脑袋,按住…

标志寄存器EFLAGES

EFLAGES是32位&#xff0c;对我们比较有用的是低16位 OF&#xff1a;溢出标志。溢出为1&#xff0c;否则为1DF&#xff1a;方向标志。串处理指令的方向IF&#xff1a;中断标志AF&#xff1a;辅助进位标志。进位时为1&#xff0c;否则为0ZF&#xff1a;零标志。运算结果为0时为1…

去除对象中的类型集合

一般来说&#xff0c;当某一个对象有多个集合类型的子元素时&#xff0c;我们都会给每个子元素创建一个集合对象来承载子元素&#xff0c;类似于&#xff1a; publicclassProcess {publicvar isExecutable:Boolean;publicvar refLaneSet:LaneSet;publicvar startEventList:Arra…

服务器安装centos6 linux,CentOS6.5安装详细教程,手把手教你安装Linux操作系统(CentOS6.5)...

CentOS6.5安装详细教程1、准备好CentOS-6.5.iso文件&#xff0c;并刻录到光盘中&#xff0c;放入光驱&#xff0c;重启服务器&#xff0c;修改BIOS为光驱启动&#xff0c;之后开始进入安装&#xff1a;2、按任意键&#xff0c;进入引导菜单。按上下键&#xff0c;移动光标&…

Vestigium-Google CodeJam 2020资格回合问题1解决方案

Problem statement: 问题陈述&#xff1a; Vestigium means "trace" in Latin. In this problem we work with Latin squares and matrix traces. Vestigium在拉丁语中表示“痕迹”。 在此问题中&#xff0c;我们使用拉丁方和矩阵迹线。 The trace of a square mat…

装修(43天,安装新家具啦)

装修(43天,安装新家具啦) 昨天保洁公司的来做了保洁.说好是9点钟让我去开门的,可他们却10点才到,原来听错地点了.三个人,从早上10开始做,到下午六点我去的时候,还没有做完,大概要做到七点.才150元钱,也真难为他们,还有一部分是公司的.效果觉得还是一般,有些地方还是不干净.可能…

dbms和sql_DBMS | 并发控制和各种并发控制方法

dbms和sql并发控制 (Concurrency Control) The concurrency control is the coordination of the simultaneous execution of a transaction in a multiuser database system. The concurrency control can ensure the serializability of the transaction in a multiuser data…

修改窗口图标 AfxRegisterWndClass()

LPCTSTR AFXAPI AfxRegisterWndClass(UINT nClassStyle,HCURSOR hCursor 0,HBRUSH hbrBackground 0,HICON hIcon 0 ); 可以简单修改一个窗口的注册类&#xff0c;当然也可以用SetWindowsLong()来实现。转载于:https://www.cnblogs.com/magic-cube/archive/2011/05/05/2038…

linux停止ssh服务的命令,开启、关闭、查看SSH服务

一、临时启用SSH服务1、通过SSH服务器的启动脚本文件启动SSH服务通过OpenSSH服务器的脚本文件“/etc/rc.d/init.d/sshd”启动SSH服务&#xff0c;命令执行如下。/etc/rc.d/init.d/sshd start命令执行后&#xff0c; SSH服务开始运行。2、使用Linux下的service命令启动SSH服务使…

XCHE命令

功能&#xff1a; 交换数据&#xff0c;交换两个操作数内容 形式&#xff1a; xche reg,reg xche reg,mem xche mem,regreg&#xff1a;寄存器&#xff1b;mem&#xff1a;内存单元 比如&#xff1a; xche eax&#xff0c;ebx;交换eax和ebx的内容 xche eax,[ebx]