+ Reply to Thread
Results 1 to 2 of 2

Thread: Please provide usage of MFC's CMap class.

  1. #1

    Please provide usage of MFC's CMap class.

    Please provide usage of MFC's CMap class.

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Posts
    109
    CMap is one of the collection classes of MFC.

    It provides you to store Key and Value pair as like std::map container. CMap works like a hash table.

    Example:


    Code:
    void CMyDialog::UsingMap()
    {
    	CMap<int, int, CString, CString> objIntsToStringMap ;
    
    	for (int nIndex=0; nIndex<10; nIndex++)
    	{
    		CString strText ;
    		strText.Format("Item %d", nIndex) ;
    		objIntsToStringMap[nIndex] = strText ;
    	}
    
    	for (nIndex=0; nIndex<objIntsToStringMap.GetCount(); nIndex++)
    	{
    		CString strText = objIntsToStringMap[nIndex] ;
    	}
    
    	CString strItem ;
    	objIntsToStringMap.Lookup(5, strItem) ;
    
    	objIntsToStringMap.RemoveKey(5) ;
    
    	POSITION objPosition = objIntsToStringMap.GetStartPosition() ;
    	while (objPosition != NULL)
    	{
    		objIntsToStringMap.GetNextAssoc(objPosition, nIndex, strItem) ;
    	}
    
    	objIntsToStringMap.RemoveAll() ;
    }
    Note:
    You will need to include #include <afxtempl.h> header file.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts