| | |
Simple Map Question
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2007
Posts: 58
Reputation:
Solved Threads: 2
Hello everyone,
I am new to maps and I have a simple question.
I have a map that stores a string as key and the data I want a map<int, int>
so my syntax is
map<string, map<int, int> test;
What would be the syntax to insert say "hello" and say 3,3?
test.insert( make_pair("hello", ???
Im stuck here.
Also, how would I display the contents?
map<string, map<int, int> >::iterator iter;
iter = test.begin();
cout << iter->first << endl;
cout << (int)iter->second->first;?????
Thanks for your help.
I am new to maps and I have a simple question.
I have a map that stores a string as key and the data I want a map<int, int>
so my syntax is
map<string, map<int, int> test;
What would be the syntax to insert say "hello" and say 3,3?
test.insert( make_pair("hello", ???
Im stuck here.
Also, how would I display the contents?
map<string, map<int, int> >::iterator iter;
iter = test.begin();
cout << iter->first << endl;
cout << (int)iter->second->first;?????
Thanks for your help.
Last edited by ff4930; Jun 24th, 2008 at 11:49 am.
>What would be the syntax to insert say "hello" and say 3,3?
Don't forget that you need to create a new map for the second half of the pair.
>Also, how would I display the contents?
Once again, remember that the second half of the pair is a completely separate map. iter->second gives you the map object, not an iterator.
C++ Syntax (Toggle Plain Text)
test.insert ( make_pair ( "hello", map<int, int>() ) ); test["hello"].insert ( make_pair ( 3, 3 ) );
>Also, how would I display the contents?
C++ Syntax (Toggle Plain Text)
map<string, map<int, int> >::iterator iter = test.begin(); cout<< iter->first <<'\n'; cout<< iter->second[3] <<'\n';
I'm here to prove you wrong.
![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Sharing Files in a Workspace Networking (Networking Hardware Configuration)
- Keeping a map of IP, Mac and Port number (Networking Hardware Configuration)
- Mashups (IT Professionals' Lounge)
- Coldfusion MX Video??? (ColdFusion)
- Unattended Installation Over The Network! (Networking Hardware Configuration)
- How do you apply/use the OSI MODEL? (Networking Hardware Configuration)
- Maps in VC++ 6.0 (C++)
- This Should be Easy for You Guys! (Linux Servers and Apache)
- OOL is amazin' (Networking Hardware Configuration)
Other Threads in the C++ Forum
- Previous Thread: How do I put C++ to work?
- Next Thread: C++ Code for hashing operations
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






