View Single Post
Old 03-31-2003, 10:57 AM   #4 (permalink)
Unicorn
Registered User
 
Unicorn's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 11
Unicorn is on a distinguished road
To look for something in a container, you can use the 'find' function from the <algorithm> header. To look for a word in your vector, you can use it like this:

Code:
vector<string>::iterator found (std::find (taboo.begin(), taboo.end(), some_word));
'found' will now point to the word you were looking for, or to 'taboo.end()' if it wasn't found.

If all the words in your taboo list are unique, consider using a set instead. A set will sort its elements for you, and you can be sure you are not wasting precious memory by storing the same word twice. Also, because the container is sorted, looking for a certain word is a lot faster.

Code:
set<string> taboo_set;
taboo_set.insert ("foo");

if (taboo_set.count ("bar") == 0)
  // The word "bar" is not in the map
Unicorn is offline   Reply With Quote