Re: STL vector help needed.
From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 02/18/04
- Next message: Dark Alchemist: "Re: STL vector help needed."
- Previous message: nog: "Re: Declaring many objects"
- In reply to: Dark Alchemist: "Re: STL vector help needed."
- Next in thread: Dark Alchemist: "Re: STL vector help needed."
- Reply: Dark Alchemist: "Re: STL vector help needed."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 18 Feb 2004 17:26:09 +0000
In message <4033879C.4B1E76E2@mysticglow.com>, Dark Alchemist
<darkalchemist@mysticglow.com> writes
>Alright, what I want to do is kill 2 vectors.
No idea what that means
>
>The way I have always done the vectors is make 2, 3, 5, 15, 100, or
>however many and once you find one value you take its iterator-begin and
>you know where to precisely grab all the records associated with it.
And again that means nothing to me. A vector (like other container
types) has a member function begin() that returns an iterator to the
first element of the vector. So in your code your places has a
places.begin() that returns an iterator to the first element of places.
Because a string is a kind of container, strings also have a begin()
member that 'points' to the first char in a string object. That has
nothing to do with your places.
> I
>do not wish to use a map, or a list and a structure seems ideal for this
>purpose but vectors, structs/classes and myself are not getting along.
No, because to be blunt, you have not got an adequate mental map of what
you are doing.
>
>Hope someone can explain, besides fussing over semantics about naming
>conventions.
>
>Real code, real problem.
And if you bothered to read the responses you got real answers. If you
want to find the element which contains a particular name you will have
to search for that name. That means you must
1: Iterate over the container (in this case your 'places')
2: provide a suitable predicate.
Yes, I guess you do not know what I am talking about but that makes me
think that you are quite some way from writing real code.
Let me try to put it simply, you need to search your places container
for a 'country' whose name 'field' is "Joe Smyth"
The find algorithm is not designed to deal with this as it searches a
range for an exact match. With experience you can hammer together a
search using find_if but you will almost certainly have to use bind1st
or bind2nd to construct an appropriate predicate from some other user
written function. With respect, your code suggests that you need a bit
more experience before trying that.
>
>Thank you to the ones who tried to help.
Perhaps you could explain what it is you want to do because at the
moment you seem fixated on problems in a tentative solution. Those
problems are almost entirely the result of the 'solution'. Learning to
select the right tool is an important part of programming and from where
I am sitting you do not seem to be using the right tool. Certainly find
is not the tool for finding an element of a vector that matches on a
single field of a struct or class.
-- Francis Glassborow ACCU Author of 'You Can Do It!' see http://www.spellen.org/youcandoit For project ideas and contributions: http://www.spellen.org/youcandoit/projects
- Next message: Dark Alchemist: "Re: STL vector help needed."
- Previous message: nog: "Re: Declaring many objects"
- In reply to: Dark Alchemist: "Re: STL vector help needed."
- Next in thread: Dark Alchemist: "Re: STL vector help needed."
- Reply: Dark Alchemist: "Re: STL vector help needed."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|