Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknown quantity at this point (<10) Stop

H

HAOBBoy

Hello

I am using a MAP as an associative array. The map automatically sorts
by key. How can I stop this feature. I will may value as FIFO. I mean
if I have the keys

Key=value

SSN=000-00-0000
Name=JAA
Age=66

When I iterate through the map I don't want may data to print as

Age
NAME
SSN

I want it to be as is:
SSN
NAME
AGE
 
M

Mark P

Hello

I am using a MAP as an associative array. The map automatically sorts
by key. How can I stop this feature. I will may value as FIFO.

You can't. That's what a map does. If you don't want this feature, use
something that isn't sorted. std:vector and std::list would each work
find for your apparent purposes. You'll need to make your own datatype
to hold the key-value pairings.

Mark
 
E

Earl Purple

Mark said:
(e-mail address removed) wrote:

You can't. That's what a map does. If you don't want this feature, use
something that isn't sorted. std:vector and std::list would each work
find for your apparent purposes. You'll need to make your own datatype
to hold the key-value pairings.

Mark

To maintain order and also have a fast lookup, you need to create an
index and there is a boost library that will do that, although if you
just want one index, it's easy enough to implement your own.

Just have the vector in the regular order, and a map from keys to the
addresses of elements in the vector (safe as long as the vector is
built once then subsequently only referenced). Alternatively you can
have map from key to the position (index) within the vector. (map<K,
std::vector<T>::size_type > where T is your type and K is your key
type).
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top