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

A

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?
Aparna :)
 
A

Alf P. Steinbach

* 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> >
 
F

ferdinand.stefanus

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.
 
S

Sumit Rajan

aparna said:
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.
 
F

ferdinand.stefanus

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> >
 
J

jesper

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;}
};
)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top