使用向量插入地图的值

时间:2012-08-22 00:03:15

标签: c++ map vector

我有以下地图:

std::map<u_long, std::vector<CChatContainer*> >m_Container;

class CChatContainer
{
public:
    CChatContainer()
    {
        m_uStartPos = 0;
        m_uEndPos = 0;
        m_dwColor = NULL;
        m_pItemElem = NULL;
    }
    ~CChatContainer(){};

    u_long m_uStartPos;
    u_long m_uEndPos;
    DWORD m_dwColor;
    void* m_pItemElem;
};

如何在其中插入值,向量部分对我来说似乎非常复杂

1 个答案:

答案 0 :(得分:1)

示例:

u_long j = 2; // get index in the map - where to insert
std::vector<CChatContainer*> conts; // create container to insert
for( int i = 0; i < N; i++ ) { // fill the container
  CChatContainer* new_cont = new CChatContainer;
  cont.push_back(new_cont);
}

m_Container[j] = conts; // insert