-
Using find() for vectors
hi ppl...
i have a vector of nodes called treenodes...ive just stored a node with the name 'pat' in it...everything else is as defined below:
Code:
char word[256];
ifstream in(filename);
in >> word; //this has pat in it...
//i make a new node with the name pat and push it onto the treenodes vector
vector< TreeNode * >::iterator j = find(treenodes.begin(),treenodes.end(),word);
cout << (*j)->name;
the vector iterator line causes a runtime error...and Borland points me to string.h saying something about size of string...
when i try to do the above by using a for loop it works...
Code:
for(vector< TreeNode * >::iterator j = treenodes.begin(); j != treenodes.end(); j++)
{
cout << (*j)->name;
}
what's wrong with the first one?
Regards,
Farooq
-
ok i get it that the last argument to find is wrong...how can i get the iterator pointing to the node with the name as in word? i.e. i want the node with the same name as in word...if i find it i do something and if i don't find it i do something else...
i want to put a condition like this inplace of word:
Code:
((*j)->name == word)
how to do this?
Regards,
Farooq
-
nevermind...ill just use a map...pair will be node name and node itself...
thanks anyway
Farooq