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

后端 未结 18 2207
滥情空心
滥情空心 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:05

    template  bool IsInVector(const T & what, const std::vector & vec)
    {
        return std::find(vec.begin(),vec.end(),what)!=vec.end();
    }
    

提交回复
热议问题