468,241 Members | 1,593 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,241 developers. It's quick & easy.

what datatypes of key can be used in c++ maps?

I want to used datastructure in which key value i want to use is
String pointer & associated with each key there is one dimensional
integer array which i want dynamic because size of integer array may be
variable .So can anyone suggest me can I use maps or what datastructure
will be suitable?
Aparna :-)

Feb 9 '06 #1
5 1358
* aparna:
I want to used datastructure in which key value i want to use is
String pointer & associated with each key there is one dimensional
integer array which i want dynamic because size of integer array may be
variable .So can anyone suggest me can I use maps or what datastructure
will be suitable?


std::map< std::string, std::vector<int> >

--
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?
Feb 9 '06 #2
map<string, int*> may be suitable. Or you can wrap int* in a smart
pointer. Just note that if you use string* as the key, that means you
are using address of a string as the key instead of the actual content
of the string.

Feb 9 '06 #3

"aparna" <ap********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I want to used datastructure in which key value i want to use is
String pointer & associated with each key there is one dimensional
integer array which i want dynamic because size of integer array may be
variable .So can anyone suggest me can I use maps or what datastructure
will be suitable?


Why don't you use a std::map<std::string, std::vector<int> >?

Regards,
Sumit.

Feb 9 '06 #4

ferdinand.stefa...@gmail.com wrote:
map<string, int*> may be suitable. Or you can wrap int* in a smart
pointer. Just note that if you use string* as the key, that means you
are using address of a string as the key instead of the actual content
of the string.


Or better yet, as other people have mentioned, use map<string,
vector<int> >

Feb 9 '06 #5
The way I read it you want to a map<std::string*,std::vector<int> >. (A
reference to a string pointer)
This is also fine but you need to think a bit about what you are doing.

In effect this maps a vector to the memory address where your string
object resides.

Be sure to declare a comparator if you want to sort your map.
(
something like:
class CompareStringPointers
{
bool operator()(const std::string* A,const std::string* B ) const
{return *A<*B;}
};
)

Feb 9 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jeff Sandys | last post: by
35 posts views Thread by Sunil | last post: by
21 posts views Thread by Helge Jensen | last post: by
16 posts views Thread by SLIMSHIM | last post: by
2 posts views Thread by rn5arn5a | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.