By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,193 Members | 826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,193 IT Pros & Developers. It's quick & easy.

How to perform Map Implemantation in C++

P: 93
Say for example I want to store the name of object and corresponding value
for the same; all in the form of strings.

How can I implement it, so that I would be able to retrieve the value once
I find the Object name.

Please Can anyone explain me with an Example ?

Thanks in advance.
Jun 6 '07 #1
Share this Question
Share on Google+
3 Replies


gpraghuram
Expert 100+
P: 1,275
HI,
I presume that u are asking for example with STL map.
Expand|Select|Wrap|Line Numbers
  1. map<string,string> smap;
  2. string s1("index");
  3. string s2("value");
  4. smap[s1]=s2;
  5.  
If u need some thing else then explain more on that..
Thanks
Raghuram
Jun 6 '07 #2

P: 93
HI,
I presume that u are asking for example with STL map.
Expand|Select|Wrap|Line Numbers
  1. map<string,string> smap;
  2. string s1("index");
  3. string s2("value");
  4. smap[s1]=s2;
  5.  
If u need some thing else then explain more on that..
Thanks
Raghuram
Thanks for your response, Your right I am asking for STL map.
The scenario is like this ...
I nead map < objname , map1 > // here map1 is value for objname
map1 < propertyname , value > // actual value comes here.

What exactly I mean is -> I should have a name value pair, in this the value
should again be a map with name value pair and here I will find the actual value

Thanks in advance,
Girish.
Jun 6 '07 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
All map elements must be pairs.

Expand|Select|Wrap|Line Numbers
  1. map<string,string> smap;
  2. pair<string, string> p;
  3. p.first = "index";
  4. p.second = "value";
  5. smap.insert(p);
  6. //
  7. //To retreive:
  8. //
  9. //
  10. map<string, string>::iterator answer;
  11. //
  12. answer = smap.find("index");
  13.  
  14. cout << (*answer).first<< endl; //you see value
  15.  
Jun 6 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.