查找list容器中的某一个值
#include#include#include#includeusing namespace std;/**编写一个Strig 类型的list,在该容器中寻找一个特殊值,如果找到则删除**/void Print(list::iterator beg,list::iterator end){ while (beg!=end) {
#include <iostream>
#include <vector>
#include <list>
#include <string>
using namespace std;
/**
编写一个Strig 类型的list,在该容器中寻找一个特殊值,如果找到则删除
**/
void Print(list<string>::iterator beg,list<string>::iterator end)
{
while (beg!=end)
{
cout<< *beg++<<" ";
}
cout<<endl;
}
void Delete(list<string>&lst,string str )
{
list<string>::iterator beg=lst.begin();
while (beg!=lst.end())
{
if (*beg==str)
beg=lst.erase(beg);
else
beg++;
}
}
int main()
{
string str[10]={"you","will","when","pray","believe","many","we","pray","with","no"};
list<string>ilist(str,str+10);
Print(ilist.begin(),ilist.end());
string deleteStr="pray";
Delete(ilist,deleteStr);
Print(ilist.begin(),ilist.end());
}
更多推荐
所有评论(0)