|
-
October 10th, 2002, 08:30 AM
#1
Understanding the map template
I am attempting to understand how to use the MAP (caps for emphasis) standard template. I have figured out how to create a multimap, and how to add items to it, but I am having difficulty trying to reread the multimap. The map declaration looks like this:
#include <map>
#include <string>
#include <iostream>
// Using a string object for both the key
// and the item
typedef multimap<string, string> NameList;
typedef NameList::iterator NameIt;
NameList Names;
NameIt CurrentName;
// An example of adding one element
// to the map:
string NameA1 = "Patty Anderson";
string NameA2 = "Anderson";
Names.insert(NameList::value_type(NameA2, NameA1));
// This is the code I am trying to use to
// output the list to the console:
for(CurrentName = Names.begin(); CurrentName != Names.end(); CurrentName++);
{
// Program crashes here.
cout << (*CurrentName).second << endl;
}
When I get to the cout line of code, the program blows up, even though I am practically copying the line from the VC++ example in their help files.
Can anyone tell me what they think I am doing wrong?
TIA.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|