Hey all!
I'm trying to figure out how to check if an element already exists in a vector.
EXAMPLE:
Elements in the vector are: "Dog", "Cat", "Fish", "Bird"
If a user tries to add (case ignored) "Dog", "dog" or any other variation, I want it to spit out and error stating it already exists.
If a user tries to add (case ignored)"Elephant", I want it to properly add it to the vector in all lowercase letters.
The vector will be sorted alphabetically after all additions have been made.
Essentially, this is what I have but as you can see is incomplete. I've got myself (and brain) stuck into a logical loop.
vector<string> wordDictionary;
void addWord(string word) {
int i;
if (!wordDictionary.empty()) {
for (i = 0; i < wordDictionary.size(); i++) {
string tmpString = wordDictionary[i];
if (strcmpi(tmpString.c_str(), word.c_str()) == 0) {
if
break;
}
wordDictionary.push_back(word);
}
} else {
wordDictionary.push_back(word);
}
}
any ideas?