473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1511
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jeff Sandys | last post by:
I'm trying to write a mapping function for genealogy. I want to read a gedcom database and plot an icon at a geographic location based on a user's query. Can you help me find: 1) A python...
3
by: Sean | last post by:
Have you ever wanted to add the great features inherent in Google Maps? Here is how you do it. ============== == STEP ONE == ============== Create a new MS Access form called frmGoogleMap....
35
by: Sunil | last post by:
Hi all, I am using gcc compiler in linux.I compiled a small program int main() { printf("char : %d\n",sizeof(char)); printf("unsigned char : ...
3
by: madsen | last post by:
Hi, I am a developper who needs to return a collection of different datatypes. Have considered using an array containing arraylists. Is it posible? or is there a better way? Would like to use some...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
21
by: Jim Langston | last post by:
I'm sure this has been asked a few times, but I'm still not sure. I want to create a function to simplify getting a reference to a CMap in a map. This is what I do now in code: ...
16
by: SLIMSHIM | last post by:
Hi, I"m new to c# and .net. I wrote a small program to add rows to an access table. the program goes thru the motions but the data never gets there. here is my code. I am intentionaly not using...
2
by: rn5arn5a | last post by:
I am not sure where I should have posted this question in this newsgroup. Please excuse me if I am wrong. Nowadays, a lot of websites have come with Maps (Google Maps being an example). Can...
3
by: Phil Stanton | last post by:
I have a button on a form which when pressed displays a google map of the address. Code is Private Sub Googlemap_Click() MakeURL ("") End Sub
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.