如何将数据插入std :: map并在vc6中显示std :: map中的数据

时间:2011-08-16 03:26:31

标签: c++ mfc

我正在使用vc6。以下代码有什么问题,我无法找到:

std::map<int, std::vector<int> > myTemplate; 

//append data to map
int temp=0;
for (int i=0;i<=5;i++)
{
    std::vector<int> tempVector;
    temp+=111;
    tempVector.push_back(temp);
    std::pair<int, std::vector<int> > myPair;
    myPair=std::make_pair(i,tempVector);
    myTemplate.insert(myPair);
}

//show data from map
std::map<int, std::vector<int> >::iterator iter;
iter=myTemplate.begin();
while(iter!=myTemplate.end());
{
    std::vector<int> tempVector;
    std::vector<int>::iterator sencondIter=iter->second.begin();
    int myValue=*sencondIter;
    CString cstrTemp;
    cstrTemp.Format("%d is the int type value in vector<int>",myValue);
    AfxMessageBox(cstrTemp);

    iter++;
}

2 个答案:

答案 0 :(得分:8)

while导致无限循环后的分号

while(iter!=myTemplate.end()); // <-----------------------

删除它。

答案 1 :(得分:1)

我建议您在此处查看Microsoft Visual Studio Express:http://en.wikipedia.org/wiki/Microsoft_Visual_Studio_Express

有关MS Visual Studio IDE的更新版本