How to find out if an item is present in a std::vector?

后端 未结 18 2233
滥情空心
滥情空心 2020-11-22 05:31

All I want to do is to check whether an element exists in the vector or not, so I can deal with each case.

if ( item_present )
   do_this();
else
   do_that(         


        
18条回答
  •  误落风尘
    2020-11-22 06:25

    If you wanna find a string in a vector:

        struct isEqual
    {
        isEqual(const std::string& s): m_s(s)
        {}
    
        bool operator()(OIDV* l)
        {
            return l->oid == m_s;
        }
    
        std::string m_s;
    };
    struct OIDV
    {
        string oid;
    //else
    };
    VecOidv::iterator itFind=find_if(vecOidv.begin(),vecOidv.end(),isEqual(szTmp));
    

提交回复
热议问题