void testMap()
{
map mymap;
map::iterator rit;
mymap["x1"] = 100;
mymap.insert(pair("y2",150));
mymap["y2"] = 200;
mymap["y2"] = 400; // this value will replace previous one.
rit = mymap.find("xx");
if ( rit !=mymap.end() ) // found id
{
rit->second= 11111; // change existing content
}else // not found
{
mymap.insert( pair("xx",150) );
}
// show content:
for ( rit=mymap.begin() ; rit != mymap.end(); rit++ )
cout << rit->first << " => " << rit->second << endl;
}
{
map
map
mymap["x1"] = 100;
mymap.insert(pair
mymap["y2"] = 200;
mymap["y2"] = 400; // this value will replace previous one.
rit = mymap.find("xx");
if ( rit !=mymap.end() ) // found id
{
rit->second= 11111; // change existing content
}else // not found
{
mymap.insert( pair
}
// show content:
for ( rit=mymap.begin() ; rit != mymap.end(); rit++ )
cout << rit->first << " => " << rit->second << endl;
}
Comments
Post a Comment