Partilhar via


CMap::SetAt

The primary means to insert an element in a map.

void SetAt(
   ARG_KEY key,
   ARG_VALUE newValue 
);

Parameters

  • ARG_KEY
    Template parameter specifying the type of the key parameter.

  • key
    Specifies the key of the new element.

  • ARG_VALUE
    Template parameter specifying the type of the newValue parameter.

  • newValue
    Specifies the value of the new element.

Remarks

First, the key is looked up. If the key is found, then the corresponding value is changed; otherwise a new key-value pair is created.

Example

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);
}

// Print the element values.
pos = myMap.GetStartPosition();
while (pos != NULL)
{
   myMap.GetNextAssoc(pos, nKey, pt);
   _tprintf_s(_T("Current key value at %d: %d,%d\n"), 
      nKey, pt.x, pt.y);
}      

Requirements

Header: afxtempl.h

See Also

Reference

CMap Class

Hierarchy Chart

CMap::Lookup

CMap::operator [ ]

Other Resources

CMap Members