Kitty said:
Hello.
Given vector<Object>, I would like to find the position of an element "obj"
in this container. What function should I use? Thanks.
Do you want an iterator that points to the object in the vector or the
actual numeric index? If an iterator is what you want, you can call the
std::find() function.
std::vector<Object> vObjects;
// add some Objects into the vector...
std::vector<Object>::iterator it = std::find(vObjects.begin(),
vObjects.end(), obj);
if(it != vObjects.end()){
// then the iterator "it" is ok to use...
}
details at:
http://www.sgi.com/tech/stl/find.html
If an iterator isn't what you want, you could always write a for loop,
incrementing the positions until you find the one that matches "obj".
Then that would give you your position as a numeric index.