#include <iostream>
#include <list>
#include <algorithm>
usingnamespace std;
//Assuming there is a class named Something which was already declared
int main(){
list<Something> List;
list<Something>:: iterator iter;
iter=find(List.begin(), List.end(), SomeVale);
//....
}
Now I want to have a condition which check whether the object was found or not.
How do I implement it by using the iterator? If Ill write:
if(iter) do_something;
Then the compile will generate me an error. Why would the compiler do it? Isn't the iterator is "sort of a pointer"?
?? it works with regular pointer and iterator if a-kind-of-a-pointer
You are wrong. It does not work with regular pointers. It works only if a function is designed such a way that it returns null pointer in case it did not find the target element.