Check if element is in the list (contains)

后端 未结 7 1943
南笙
南笙 2021-01-31 14:38

I\'ve got a list of elements, say, integers and I want to check if my variable (another integer) is one of the elements from the list. In python I\'d do:

my_list         


        
相关标签:
7条回答
  • 2021-01-31 15:28

    Use std::find, something like:

    if (std::find(std::begin(my_list), std::end(my_list), my_var) != std::end(my_list))
        // my_list has my_var
    
    0 讨论(0)
提交回复
热议问题