473,394 Members | 1,956 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,394 software developers and data experts.

passing through all elements in hash

i have a big hash like the following

map<string, int> TESTHASH;

how do i pass through each key of the hash and get its value ?

kinda like foreach(keys(%TESTHASH)) in perl

but how do i go about this in c++ ?

i already populated my hash and i am able to pull out the values with
the keys, but in this case, i dont know the keys and i want c++ to
figure that out for me.. but i dont know how to figure this out :-)

thanks

Sep 14 '05 #1
4 1325

mahur...@gmail.com wrote:
i have a big hash like the following

map<string, int> TESTHASH;

how do i pass through each key of the hash and get its value ?

kinda like foreach(keys(%TESTHASH)) in perl

but how do i go about this in c++ ?

i already populated my hash and i am able to pull out the values with
the keys, but in this case, i dont know the keys and i want c++ to
figure that out for me.. but i dont know how to figure this out :-)

thanks


You can iterate through the container and print the keys thusly:

for( map<string,int>::const_iterator i=TESTHASH.begin();
i != TESTHASH.end();
++i )
{
cout << i->first << endl;
}

Cheers! --M

Sep 14 '05 #2
aah.. perfect

i->second is giving me the value for that key (just did some
experimenting and it worked) :-)

thanks

Sep 14 '05 #3
ma******@gmail.com wrote:
aah.. perfect

i->second is giving me the value for that key (just did some
experimenting and it worked) :-)

thanks


Not it isn't, you've got your key and your value mixed up.

In this

map<string, int>

The string is the key and the int is the value.

john
Sep 14 '05 #4
oh.. i really meant the same thing

i->first ==> key (string)

i->second ==> "value for that key" (int)
John Harrison wrote:
ma******@gmail.com wrote:
aah.. perfect

i->second is giving me the value for that key (just did some
experimenting and it worked) :-)

thanks


Not it isn't, you've got your key and your value mixed up.

In this

map<string, int>

The string is the key and the int is the value.

john


Sep 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jjl | last post by:
I have an array, and try to find out the unique elements (case insentitive) of array. Could someone help me out. Thanks a lot.
1
by: Mike King | last post by:
Is there a way to create a hash of an element with all of its descendants? I want to uniquely identify an element within a XML document not by its position but by its content (not concatenated...
14
by: Alex Vinokur | last post by:
Here is some function that detects if a vector contains only different elements bool vector_contains_only_different_elements (const vector<int>& v) { for (int i = 0; i < v.size(); i++) { if...
0
by: Dirty Sanchez | last post by:
Hey Ladies, I have been working on a DES encryption module and have an issue. When I create keyhash (an MD5 hash of the keystring) and attempt to copy the first 8 bits of the byte array to...
24
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
4
by: lokki | last post by:
Hello, can anybody tell me what's wrong with following example code? char *k, *v; k = new char; strcpy(k, "a2"); v = new char;
0
by: wellingj | last post by:
A little back ground on what I'm trying to do: I'm making a generic weighted graph class (vertexes and edges althought I don't call them that) to implement some pathfinding algorithms like A* and D*....
4
by: digidig | last post by:
Hi, I'm coding a hash algorithm (SHA-1) in C. The algorithm works, everything compiles and I seem to be getting the correct results when I simulate it. I obviously want to automate the checking...
0
by: AK | last post by:
Hello, I need to do the following with an xml document which has a list of assets: 1. Hash the assets 2. Hash the element describing the assets 3. Create a digital signature (using X.509...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.