#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());

 

 

 

 


 
}

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐