Search code examples
multimapc++builder-2010

Form freezes when using multimap


What's wrong with what I am doing in the following unit code?

The form freezes when I run this code, with no message output.

//---------------------------------------------------------------------------

#include <vcl.h>
#include <map.h>
#pragma hdrstop

#include "Unit1.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btn1Click(TObject *Sender)
{
    typedef multimap<AnsiString,int> TMM;
    TMM mm1;
    mm1.insert(TMM::value_type("Vasya Vasya",1954));
    mm1.insert(TMM::value_type("Ivan Petr",1985));
    mm1.insert(TMM::value_type("Hasan Husein",1983));
    mm1.insert(TMM::value_type("Julia Mck",1982));

    AnsiString s="";
    TMM::iterator it=mm1.begin();
    while (it!=mm1.end())
    {
        s+=(*it).first+ "-"+ IntToStr((*it).second)+"\n";
    }
    ShowMessage(s);



}
//---------------------------------------------------------------------------

Solution

  • You need to increment the iterator inside the while loop