c++ - 如何将数据插入 std::map 并在 vc6 中显示来自 std::map 的数据

标签 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++;
}

最佳答案

while 后的分号导致无限循环

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

删除它。

关于c++ - 如何将数据插入 std::map 并在 vc6 中显示来自 std::map 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7073332/

相关文章:

c++ - 在纯 native 代码中使用托管对象

c++ - OnDestroy 中的 DestroyWindow 不起作用

c++ - boost::regex 库中的内存泄漏

c++ - 在 elf 文件中查找全局变量的位置

C++ 在 map 上循环 - 消失的对象

c++ - CMFCPopupMenu - 右键单击​​上下文菜单快捷键由于某种原因消失

c++ - 对象级 CSingleLock 与方法级 CSingleLock

c++ - 如何获取嵌入式IE ActiveX控件的版本?

c++ - 在 C++ 中使用变量作为数组参数

c++ - 动态二维数组分配