2011-11-30 73 views
0

我在下面的单元代码中做了什么错?当使用multimap时表单冻结

当我运行此代码时,表单冻结,没有消息输出。

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

#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); 



} 
//--------------------------------------------------------------------------- 
+0

中,虽然里面的迭代器,你用'mm1.begin()'和'mm1.end()',但你没有使用'MM1。 next()'或类似的东西来遍历'mm1'。不是吗? – gustavotkg

+0

是的,我错过了在循环内增加'it'! –

回答

2

你需要增加while循环

+0

是的,我没有在循环内增加'it'!这是问题所在。谢谢 –