怎样使用cmap,怎样用new申请个cmap空间,写出示例,需要什么头文件

解决方案 »

  1.   

    CMap<UINT, UINT, CString, CString> *m_map1;
    m_map1 = new CMap<UINT, UINT, CString, CString>;
    m_map1->SetAt(0x01,"001") ;
    m_map1->SetAt(0x02,"002") ;
    m_map1->SetAt(0x03,"003") ;CString sValue;
    m_map1->Lookup(0x01,sValue);delete m_map1;建议,直接在堆上面申请更简单
    头文件
    #include <afxtempl.h>
    #include <afxcoll.h>
      

  2.   

    CMap<int,int,CPoint,CPoint> myMap;   // Add 10 elements to the map.
       for (int i=0;i < 10;i++)
          myMap.SetAt( i, CPoint(i, i) );   // Remove the elements with even key values.
       POSITION pos = myMap.GetStartPosition();
       int    nKey;
       CPoint pt;
       while (pos != NULL)
       {
          myMap.GetNextAssoc( pos, nKey, pt );      if ((nKey%2) == 0)
             myMap.RemoveKey( nKey );
       }#ifdef _DEBUG
        afxDump.SetDepth( 1 );
        afxDump << "myMap: " << &myMap << "\n";
    #endif