finding an object in a STL list
Hello.I can search for an item with a specific value thus:
1 2 3 4
|
for( list<Evaluation>::iterator it = website->results.begin();it != website->results.end();++it )
if( (strcmp( id_article,it->getArticleID() ) == 0) && (strcmp( id_arbiter, it->getArbiterID() ) == 0) )
if( strcmp( userType, "arbiter" ) == 0 )
it->edit();
|
NOTE:Evaluation is a class.results is a member of website.edit() is a member function of class Evaluation.the code compiles
but when do I know if it is not in the list?
Last edited on
You could
break;
when you find it and test
if(it == website->results.end())
to see if you reached the end or not.
1 2 3 4 5 6 7 8 9 10 11
|
for( list<Evaluation>::iterator it = website->results.begin();it != website->results.end();++it )
if( (strcmp( id_article,it->getArticleID() ) == 0) && (strcmp( id_arbiter, it->getArbiterID() ) == 0) )
if( strcmp( userType, "arbiter" ) == 0 )
{
it->edit();
break;
}
if(it == website->results.end())
{
// not in the list
}
|
Last edited on
Topic archived. No new replies allowed.