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

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

    Bear in mind that, if you're going to be doing a lot of lookups, there are STL containers that are better for that. I don't know what your application is, but associative containers like std::map may be worth considering.

    std::vector is the container of choice unless you have a reason for another, and lookups by value can be such a reason.

提交回复
热议问题