要插入的主要方式元素在映射。
void SetAt(
ARG_KEY key,
ARG_VALUE newValue
);
参数
ARG_KEY
指定 key 参数的类型模板参数。key
指定新元素的键。ARG_VALUE
指定 newValue 参数的类型模板参数。newValue
指定新元素的值。
备注
首先,查找键。 如果找到键,则更改相应的值;否则新的键/值对中创建。
示例
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);
}
要求
Header: afxtempl.h