CMapStringToString類支持CString對象爲關鍵碼的CString 對象映射。CMapStringToString的成員函數與CMapStringToOb類的成員函數相似。由於這種相似性,因此可以爲指定的成員函數使用CMapStringToOb參考。不管是否將CObject指針看作返回值,還是“輸出”函數的參數,它都會將指針替換爲字符。另外,不管是否將CString指針看作“輸出”函數參數,它都會將指針替換爲字符。
SetAt 在映射中插入一個元素,但假如發現了相匹配的關鍵碼,則替換已經存在的元素.
例如:
CMapStringToString myMap;
myMap.SetAt(key,keyValue);
POSITION ipos = myMap.GetStartPosition();
while(ipos!=NULL)
{
myMap.GetNextAssoc(ipos,key,keyValue);
if(key.CompareNoCase("path")!=0)
{
m_strHeaderInfo += _T("&")+key+_T("^")+keyValue;
}
}
例:
CMapStringToString map;
CString strTemp
map.SetAt( "Bart", "aa");
map.SetAt( "Lisa", "bb" );
map.SetAt( "Homer", "cc" );
map.SetAt( "Marge", "dd" );
ASSERT( map.Lookup( "Lisa", strTemp)); // Is "Lisa" in the map?
ASSERT( strTemp == "bb" ); // Is she 11?