Click to See Complete Forum and Search --> : Let's see if this works


proxima centaur
November 5th, 2002, 11:02 AM
#include "stdafx.h"
#include <map>
#include <string>
#include <iostream>

using namespace std;


// Using a string object for both the key
// and the item
#pragma warning ( disable : 4786 )
typedef multimap<string, string> NameList;

typedef NameList::iterator NameIt;

int main()
{
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 << static_cast<string>(CurrentName->second) << endl;

}
*/
CurrentName = Names.begin();

while( CurrentName != Names.end() )
{
cout << (*CurrentName).second;
cout << endl;
++CurrentName;
}

for( CurrentName = Names.begin(); CurrentName != Names.end(); CurrentName++ )
{
cout << (*CurrentName).second <<endl;
cout << endl;
}

return 0;
}

proxima centaur
November 5th, 2002, 11:06 AM
CFiddleDi::Prociekt()