void GetNextAssoc( POSITION& rNextPosition, CString& rKey, CObject*& rValue ) const;
rNextPosition
A reference to a POSITION value returned by a previous GetNextAssoc or GetStartPosition call.
rKey
The returned key of the retrieved element (a string).
rValue
The returned value of the retrieved element (a CObject pointer).
Retrieves the map element at rNextPosition, then updates rNextPosition to refer to the next element in the map. This function is most useful for iterating through all the elements in the map. Note that the position sequence is not necessarily the same as the key value sequence.
If the retrieved element is the last in the map, then the new value of rNextPosition is set to NULL.
CMapStringToOb map;
POSITION pos;
CString key;
CAge* pa;
map.SetAt( "Bart", new CAge( 13 ) );
map.SetAt( "Lisa", new CAge( 11 ) );
map.SetAt( "Homer", new CAge( 36 ) );
map.SetAt( "Marge", new CAge( 35 ) );
// Iterate through the entire map, dumping both name and age
for( pos = map.GetStartPosition(); pos != NULL; )
{
map.GetNextAssoc( pos, key, pa );
#ifdef _DEBUG
afxDump << key << " : " << pa << "\\n";
#endif
}
The results from this program are as follows:
Lisa : a CAge at $4724 11
Marge : a CAge at $47A8 35
Homer : a CAge at $4766 36
Bart : a CAge at $45D4 13
CMapStringToOb::GetStartPosition