STL——容器(List)list 数据的存取
2024-09-06 20:34:59
list.front();
//返回第一个元素
list.back();
//返回最后一个元素
1 #include <iostream>
2 #include <list>
3
4 using namespace std;
5
6 int main()
7 {
8 int num[] = { 111,222,333,444,555 };
9 list<int> listInt(num, num + size(num));
10
11 int iFront = listInt.front();
12 int iBack = listInt.back();
13
14 cout << "iFront的值为:" << iFront << endl;
15 cout << "iBack的值为:" << iBack << endl;
16
17 cout << "修改前遍历 listInt:";
18 for (list<int>::iterator it = listInt.begin(); it != listInt.end(); it++)
19 {
20 cout << *it << " ";
21 }
22 cout << endl;
23
24 listInt.front() = 0;
25 listInt.back() = 666;
26
27 cout << "修改后遍历 listInt:";
28 for (list<int>::iterator it = listInt.begin(); it != listInt.end(); it++)
29 {
30 cout << *it << " ";
31 }
32 cout << endl;
33
34 return 0;
35 }
打印结果:
=======================================================================================================================
最新文章
- spring bean的生命周期
- [UWP]涨姿势UWP源码——RSS feed的获取和解析
- bootstrap-datepicker的使用
- Mac 安装mysql
- 亲们! 首次见面! 带来不适!多多见谅!--------->;>;Bank系统
- 幂运算(codevs 2541)
- php发送ssl邮件
- addClass 函数
- ubuntu OPENCV移植
- Elasticsearch和mysql数据同步(elasticsearch-jdbc)
- 初次使用nodejs的问题
- 听说你又一次放弃了Dagger2,来听老夫说道说道
- Spark初步 从wordcount开始
- dump文件解析之探索.Net的内存
- Web版记账本开发记录(二)开发过程遇到的问题小结1 对数据库的区间查询
- 关于php下的ajax赋值传值的调试
- 如何从应用直接跳转AppStore 电话 短信 邮件
- Java8 (Function,Consumer,Predicate,Supplier)详解
- The last time the sprint(最后一个冲刺)
- eclipse如何设置编译后target目录不提交svn服务器