转自:http://blog.csdn.net/nupt123456789/article/details/8120397

#include <iostream>
#include <list>
#include <string>
using namespace std;
class Student{
private:
int ID;
string Name;
public:
Student(int ID,string Name)
{
this->ID=ID;
this->Name=Name;
}
int getID()
{
return ID;
}
string getName()
{
return Name;
}
};
int main()
{
// create an empty list (of zero size) capable of holding doubles
list<double> list0; cout << "Size of list0 is " << list0.size() << endl; // create a list with 5 empty elements
list<double> list1(5); cout << "Size of list1 is " << list1.size() << endl; // create a list with 5 elements, each element having the value 10.2
list<double> list2(5, 10.2); cout << "list2: ";
list<double>::iterator it;
for(it = list2.begin(); it != list2.end(); ++it)
cout << *it << " ";
cout << endl;
// create a list based on an array of elements
// only the first 5 elements of the array are copied into the vector
double array[8] = {3.45, 67, 10, 0.67, 8.99, 9.78, 6.77, 34.677}; list<double> list3(array, array + 5); cout << "list3: ";
for(it = list3.begin(); it != list3.end(); ++it)
cout << *it << " ";
cout << endl; // use the copy constructor to copy list3 list into list3copy list
list<double> list3copy(list3); cout << "list3copy: ";
for(it = list3copy.begin(); it != list3copy.end(); ++it)
cout << *it << " ";
cout << endl; // assign 5 values of 10.2 to the list
list<double> list4; list4.assign(5, 10.2); cout << "list4: ";
for(it = list4.begin(); it != list4.end(); ++it)
cout << *it << " ";
cout << endl;
//定义自己的数据类型
list<Student> list5;
Student stu1(1,"ZhengHaibo");
Student stu2(2,"nupt");
list5.push_back(stu1);
list5.push_back(stu2);
list<Student>::iterator iter_stu;
cout << "list5: "<<endl;
for (iter_stu=list5.begin();iter_stu!=list5.end();iter_stu++)
{
cout<<"ID:"<<iter_stu->getID()<<" Name:"<<iter_stu->getName()<<endl;
}
return 0;
// Output
// Size of list0 is 0
// Size of list1 is 5
// list2: 10.2 10.2 10.2 10.2 10.2
// list3: 3.45 67 10 0.67 8.99
// list3copy: 3.45 67 10 0.67 8.99
// list4: 10.2 10.2 10.2 10.2 10.2
//list5:
//ID:1 Name:ZhengHaibo
//ID:2 Name:nupt
}

上面只是一点,原文很多

vector的文章http://blog.csdn.net/nupt123456789/article/details/7482923

c++ stl list使用总结(转)的更多相关文章

  1. 详细解说 STL 排序(Sort)

    0 前言: STL,为什么你必须掌握 对于程序员来说,数据结构是必修的一门课.从查找到排序,从链表到二叉树,几乎所有的算法和原理都需要理解,理解不了也要死记硬背下来.幸运的是这些理论都已经比较成熟,算 ...

  2. STL标准模板库(简介)

    标准模板库(STL,Standard Template Library)是C++标准库的重要组成部分,包含了诸多在计算机科学领域里所常见的基本数据结构和基本算法,为广大C++程序员提供了一个可扩展的应 ...

  3. STL的std::find和std::find_if

    std::find是用来查找容器元素算法,但是它只能查找容器元素为基本数据类型,如果想要查找类类型,应该使用find_if. 小例子: #include "stdafx.h" #i ...

  4. STL: unordered_map 自定义键值使用

    使用Windows下 RECT 类型做unordered_map 键值 1. Hash 函数 计算自定义类型的hash值. struct hash_RECT { size_t operator()(c ...

  5. C++ STL简述

    前言 最近要找工作,免不得要有一番笔试,今年好像突然就都流行在线笔试了,真是搞的我一塌糊涂.有的公司呢,不支持Python,Java我也不会,C有些数据结构又有些复杂,所以是时候把STL再看一遍了-不 ...

  6. codevs 1285 二叉查找树STL基本用法

    C++STL库的set就是一个二叉查找树,并且支持结构体. 在写结构体式的二叉查找树时,需要在结构体里面定义操作符 < ,因为需要比较. set经常会用到迭代器,这里说明一下迭代器:可以类似的把 ...

  7. STL bind1st bind2nd详解

    STL bind1st bind2nd详解   先不要被吓到,其实这两个配接器很简单.首先,他们都在头文件<functional>中定义.其次,bind就是绑定的意思,而1st就代表fir ...

  8. STL sort 函数实现详解

    作者:fengcc 原创作品 转载请注明出处 前几天阿里电话一面,被问到STL中sort函数的实现.以前没有仔细探究过,听人说是快速排序,于是回答说用快速排序实现的,但听电话另一端面试官的声音,感觉不 ...

  9. STL的使用

    Vector:不定长数组 Vector是C++里的不定长数组,相比传统数组vector主要更灵活,便于节省空间,邻接表的实现等.而且它在STL中时间效率也很高效:几乎与数组不相上下. #include ...

  10. [C/C++] C/C++延伸学习系列之STL及Boost库概述

    想要彻底搞懂C++是很难的,或许是不太现实的.但是不积硅步,无以至千里,所以抽时间来坚持学习一点,总结一点,多多锻炼几次,相信总有一天我们会变得"了解"C++. 1. C++标准库 ...

随机推荐

  1. 异步技巧之CompletableFuture

    摘自--https://juejin.im/post/5b4622df5188251ac9766f47 异步技巧之CompletableFuture 1.Future接口 1.1 什么是Future? ...

  2. JAVA JVM助记符

    ldc:将int/float/String类型的常量值从常量池中推送至栈顶(栈顶的值是即将要用的) bipush:将单字节(-128 ~ 127)的常量值从常量池中推至栈顶 sipush:将一个短整型 ...

  3. Spark学习进度7-综合案例

    综合案例 文件排序 解法: 1.读取数据 2.数据清洗,变换数据格式 3.从新分区成一个分区 4.按照key排序,返还带有位次的元组 5.输出 @Test def filesort(): Unit = ...

  4. “500 oops socket” Debian 9 running via Linux Deploy上成功部署vsftpd的解决方案(201901原创)【成功完美简单极致】

    "500 oops socket" Debian 9 running via Linux Deploy上成功部署vsftpd的解决方案(201901原创)[成功完美简单极致] #自 ...

  5. NOIP初赛篇——07信息编码表示

    一.基本概念 编码 ​ 计算机要处理的数据除了数值数据以外,还有各类符号.图形.图像和声音等非数值数据.而计算机只能识别两个数字0,1.要使计算机能处理这些信息,首先必须要将各类信息转换成0与1表示的 ...

  6. 【SpringMVC】SpringMVC 实现文件上传

    SpringMVC 实现文件上传 文章源码 文件上传回顾 查看 JavaWeb 阶段的文件上传下载 实现步骤: 客户端: 发送 post 请求,告诉服务器要上传什么文件 服务器: 要有一个 form ...

  7. LeetCode561 数组拆分 I

    给定长度为 2n 的数组, 你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), ..., (an, bn) ,使得从1 到 n 的 min(ai, bi) 总和最大. 示例 ...

  8. LeetCode430 扁平化多级双向链表

    您将获得一个双向链表,除了下一个和前一个指针之外,它还有一个子指针,可能指向单独的双向链表.这些子列表可能有一个或多个自己的子项,依此类推,生成多级数据结构,如下面的示例所示. 扁平化列表,使所有结点 ...

  9. Openstack dashboard 仪表盘服务 (八)

    Openstack dashboard 仪表盘服务 (八) # 说明: 这个部分将描述如何在控制节点上安装和配置仪表板.dashboard仅在核心服务中要求认证服务.你可以将dashboard与其他服 ...

  10. MySQL常用的一些(就几个)聚合函数

    聚合函数 (常用) 函数名称 描述 CONUT() 记数 SUM() 求和 AVG() 平均值 MAX() 最大值 MIN() 最小值 -- ================= 聚合函数 ====== ...