When using an STL list, how can I check if a certain variable happens to just be in there? Basically, given this already:

#include <iostream>
#include <list>
#include <iterator>
using namespace std;
list<int> integer_list;

I need a way to code this in C++:

if(x is in integer_list){
do this }

Recommended Answers

All 2 Replies

if( std::find( alist.begin(), alist.end(), x ) != alist.end() )
{ /* do this */ }

Thanks, that worked beautifully.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.