i have a code like this….
std::vector<string>::iterator p;
p = find(v.begin(),v.end(),"asdasda");
cout << *p << endl;
if “asdasda” is not a part of the vector, p points to some garbage and cout gives a seg fault. what should be the if statement that would make the cout execute onlyif “asdasda” was found?
and also the position of “asdasda” in v.. like if we had earlier declared v[3] as “asdasda”,
then how can i know from the find that v[3] is “asdasda”?
pdoesn’t point to “garbage”, it simply becomesv.end()when the content is not found.