首页 / C++ / c++ list容器基本用法
c++ list容器基本用法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了 c++ list容器基本用法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1215字,纯文字阅读大概需要2分钟。
内容图文
![c++ list容器基本用法](/upload/InfoBanner/zyjiaocheng/648/2fcef28ab74f41efa612147e25a5a12b.jpg)
- 基本用法
#include<iostream> #include<time.h> #include<vector> #include<list> using namespace std; void main() { int a[] = {33,44,55,66,77,88}; int i; list<int> lst(a,a+5); list<int>::iterator it;//list只能用迭代器指针循环遍历 cout << endl; for (it=lst.begin();it!=lst.end();++it) { cout << *it<< " "; } cout << endl; list<int> lst2(5,0); lst2.assign(lst.begin(),lst.end()); for (it=lst2.begin();it!=lst2.end();it++) { cout << *it << " "; } list<int> lst3(6,8); int newnum[] = {10,12,24,36,46,54,99.88,111}; lst3.assign(newnum, newnum + 4); cout << endl; for (it=lst3.begin();it!=lst3.end();it++) { cout << *it << "*******"; } lst3.assign(&newnum[0], &newnum[3]); cout << endl; for (it = lst3.begin(); it != lst3.end(); it++) { cout << *it << "======"; } }
输出结果:
- 利用迭代器指针增/删元素
#include<iostream> #include<time.h> #include<vector> #include<list> using namespace std; void main() { list<int>lst3; int i; list<int>::iterator it; int newnum[] = {10,12,24,36,46,54,99.88,111}; for (i = 0; i < 5; i++) { lst3.push_back(newnum[i]); } //lst3.assign(&newnum[0], &newnum[3]); it = lst3.begin(); it++; lst3.insert(it,2,88); --it; lst3.insert(it, 666); cout << endl; for (it = lst3.begin(); it != lst3.end(); it++) { cout << *it << " "; } }
输出结果:
内容总结
以上是互联网集市为您收集整理的 c++ list容器基本用法全部内容,希望文章能够帮你解决 c++ list容器基本用法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。