c++ list中erase()操作
来源:互联网 发布:db2数据库的安装使用 编辑:程序博客网 时间:2024/05/09 01:44
#include <list>#include <iostream>int main( ) { using namespace std; list <int> c1; list <int>::iterator Iter; c1.push_back( 10 ); c1.push_back( 20 ); c1.push_back( 30 ); c1.push_back( 40 ); c1.push_back( 50 ); cout << "The initial list is:"; for ( Iter = c1.begin( ); Iter != c1.end( ); Iter++ ) cout << " " << *Iter; cout << endl; c1.erase( c1.begin( ) ); cout << "After erasing the first element, the list becomes:"; for ( Iter = c1.begin( ); Iter != c1.end( ); Iter++ ) cout << " " << *Iter; cout << endl; Iter = c1.begin( ); Iter++; c1.erase( Iter, c1.end( ) ); cout << "After erasing all elements but the first, the list becomes: "; for (Iter = c1.begin( ); Iter != c1.end( ); Iter++ ) cout << " " << *Iter; cout << endl;}
#include <iostream>#include <list>using namespace std;int main(){list<int> a;list<int>::iterator Iter;for(int i=0;i<10;i++){a.push_back(i);}cout<<"初始时:"<<endl;for(Iter=a.begin();Iter!=a.end();Iter++){cout<<*Iter<<" ";}cout<<endl;for(Iter=a.begin();Iter!=a.end();Iter++){if(4==*Iter){a.erase(Iter++);}}cout<<"删除后:"<<endl;for(Iter=a.begin();Iter!=a.end();Iter++){cout<<*Iter<<" ";}system("pause");return 0;}
(未完待续)
0 0
- c++ list中erase()操作
- 【c++】C++ list erase 错误
- C++primer学习-list中的erase函数
- 【C++】vector容器和list容器中使用单个迭代器的erase函数学习笔记
- list-erase
- 关于STL中list的erase()函数
- STL中list的erase()方法
- list中使用erase迭代器失效
- C++中list的erase()函数问题
- STL中list的erase()方法
- C++/STL_中vector基本操作测试代码,vector.erase()使用方法
- STL中map的erase操作
- 关于list容器与vector容器中的erase操作
- C++ list中erase和remove函数的用法
- C++ list中insert、erase和remove函数的用法
- STL中list的erase()方法的使用
- 一组数据,copy一份至list,一份至vector,list中erase奇数,vector中erase偶数
- list erase issue
- 冒险岛在线素材
- 单例设计模式
- LINUX小白重装上百次后, 最终找出一个成功方案 CentOS LAMP +wordpress+phpmyadmin 共0.84G
- 常用的SQL语句
- 开源网络爬虫Larbin的安装及配置
- c++ list中erase()操作
- ajax实现异步请求,不跳转页面的情况下,达到检验用户名等信息是否效果的功能!
- codeforces a 24 game
- OpenLayers访问Geoserver发布的地图
- A. I Wanna Be the Guy
- java.util.Properties 乱码问题解决方案
- 在MATLAB中读取多个文件
- 正则表达式系统教程.CHM
- SDWebImage 最新版详解