* Brad:
> New to C++. Just ran into a need to store three things in a map. Before
> trying it, I thought I'd post here and ask for advice. Here is an
> example of what I need to store:
>
> map<string name, string prefix, int length>
>
> Both name and prefix would be unique for each map entry. I was wondering
> if the the first entry could be an array that holds the two items (name
> and prefix), but then I wondered how an iterator would behave when
> it->first is called.
>
> Any suggestions or pointers on using a map with three items would be
> much appreciated.
A map is an association from key to (key, value). Abstractly it's just an
association from key to value. You need to decide what your key is, and
what
your value is. The value can be anything copyable, such as a struct with
two
members. E.g. you can have a map< string, pair<string, int> >.
Before doing that, however, it might be an idea to think through what the
problem you're trying to solve is, not how to use a map to solve it.
For example, is the 'length' the number of characters in name or prefix?
If so,
then you already have it in the name or prefix string. Or is the length
perhaps
the sum of the name and prefix lengths? In that case it's easier to
compute it
than look it up in a map. Some analysis is always good. :-)
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


|