-
map - search it
I want to search my map. If I search for a string that's not listed, it bombs for obvious reason (see the code).
How do I phrase this to do the following:
x = map.find(string)
if x != map.end
-spit it out
else
-spit out spaces.
Code:
it = freq.find ( "ofx" );
cout << it->first;
-
this works but is it the best way?
Code:
it = freq.find ( "ofx" );
if (it != freq.end())
{
cout << it->first;
}
-
That is the way I usually do it.
-
Your solution is simple, clear, and effective; stick with it.
Additionally, there is really no other way that is fundamentally different.
Cheers