码迷,mamicode.com
首页 > 其他好文 > 详细

list<> 中find的使用

时间:2014-06-15 23:55:32      阅读:386      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   color   使用   

昨天要在 std::list<std::string> 中判断是否存在某一字符串 std::string 。

 

我首先想先迭代+std::string自带的"==" 判断,也就是

    list<string>  listStr;
    string  s1; 
    for(vector<string>::iterator           itr=listStr.begin();itr!=listStr.end();itr++)
    {
        if(*itr==s1) break; 
    }
      
    if(itr!=**.end())
    {
        //干点什么
    }        

 

这种,但觉得有点麻烦,想到了list有find的,就去查了一下,测试过后得到下面的情况:

 

  

    list<string> listStr;
    string s1;
    list<string>::iterator lsItr=find(listStr.begin();listStr.end();s1);
    if(lsItr!=vetStr.end())
    {
          //干点什么
    }

    不过这里要注意 使用std的find时要 加上 #include<algorithm> 头文件

 

  

list<> 中find的使用,布布扣,bubuko.com

list<> 中find的使用

标签:style   class   blog   code   color   使用   

原文地址:http://www.cnblogs.com/sixbeauty/p/3785185.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!