设为首页 加入收藏

TOP

标准模板库(STL)List介绍(十六)
2011-06-07 12:31:23 来源: 作者: 【 】 浏览:9186
Tags:标准 模板 STL List 介绍
 
  
用list成员函数remove()从list中删除元素。  
list的成员函数remove()用来从list中删除元素。  
  
/*  
|| Using the list member function remove to remove elements  
*/  
#include <string>  
#include <list>  
#include <algorithm>  
   
PrintIt (const string& StringToPrint) {  
     cout << StringToPrint << endl;  
}  
   
int main (void) {  
     list<string> Birds;  
   
     Birds.push_back("cockatoo");  
     Birds.push_back("galah");  
     Birds.push_back("cockatoo");  
     Birds.push_back("rosella");  
     Birds.push_back("corella");  
   
     cout << "Original list with cockatoos" << endl;  
     for_each(Birds.begin(), Birds.end(), PrintIt);  
   
     Birds.remove("cockatoo");  
   
     cout << "Now no cockatoos" << endl;  
     for_each(Birds.begin(), Birds.end(), PrintIt);  
}  
  
输出是:  
  
Original list with cockatoos  
cockatoo  
galah  
cockatoo  
rosella  
corella  
Now no cockatoos  
galah  
rosella  
corella  
  
首页 上一页 13 14 15 16 17 18 下一页 尾页 16/18/18
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇 C++语言的url encode 和decode 下一篇C++ map的基本操作和使用

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: