Im making a little app for myself and inside it i use map<string,float>
Is there a way to output all value inside map even if i dont know the names of the values?
(the user input the name of each value)
?
Luigi
Im making a little app for myself and inside it i use map<string,float>
Is there a way to output all value inside map even if i dont know the names of the values?
(the user input the name of each value)
?
Luigi
>>Is there a way to output all value inside map even if i dont know the names of the values?
Sure! :-)
Code:void show_me(map<string, float>& mymap) { map<string, float>::const_iterator iter; for (iter = mymap.begin(); iter != mymap.end(); ++iter) { cout<< iter->first <<' '<< iter->second <<endl; } }
*Cela*
how does this map<string,float> work?
>>how does this map<string,float> work?
It's like a hash table, the first part of the map, in this case string, is the key and the second part is the value. You use the key to search for the value by saying
A map probably isn't implemented as an actual hash table, but that doesn't change how you use it :-)Code:mymap["blah"] = 123.456; // New entry string key = "blah"; cout<< mymap[key] <<endl; // Prints 123.456
*Cela*
when is this usefull to use?
>>when is this usefull to use?
When you need a dynamic data structure that needs something other than integer indicies, unlike a vector, and can be searched quickly, unlike a list. :-)
*Cela*
never seen this in a book b4 can u show uss another example please?
Try a search
http://www.sgi.com/tech/stl/Map.html