Re: vector question

From: Howard (alicebt_at_hotmail.com)
Date: 03/18/05


Date: Fri, 18 Mar 2005 17:44:04 GMT


"Kitty" <No spam> wrote in message news:423b0fd3$1_2@rain.i-cable.com...
> Hello.
>
> Given vector<Object>, I would like to find the position of an element
> "obj" in this container. What function should I use? Thanks.
>

If I undesrstand correctly, vector is not an "associative" container, so you
can't use find() on it. A simple loop using an iterator (or
const_iterator), and doing whatever comparison you need to check if an item
meets your requirement, should do the trick. (You don't say what you mean
by "an element 'obj'", so I'm guessing you've got some way to identify the
object you want...?)

-Howard



Relevant Pages

  • Re: STL Vector: Unexpected behavior
    ... iterator of that container. ... you could move all pointers you want to keep to a new ... you also omit checking if the pointer is zero in your loop. ...
    (microsoft.public.vc.stl)
  • Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)
    ... > while Has_Element loop ... > container, the passive iterator is preferred: ... > If you have an array type, then you can give it a container-like ...
    (comp.lang.ada)
  • Re: help a newbie with vectors
    ... I usually prefer the approach of earlier posters: ... There is nothing wrong with the above loop, but it really is a "for" ... since you are not using the iterator to ... modify the container, make it a const_iterator: ...
    (comp.lang.cpp)
  • Re: iterator invalidation trouble
    ... Iterator invalidation. ... Thus the iterator it gets invalid. ... > simply introduce a second iterator inside the for loop. ... You could use a container that only invalidates the erased element ...
    (comp.lang.cpp)
  • Re: Factoring iteration
    ... Now it's cool that the double-nested loop turns into just the one line ... grid iterator class, where the actual per-item action is a method, ... All masks with only one bit set represent a solution for that field. ... actually requires backtracking, unless you want to find all possible ...
    (comp.lang.forth)