int main ()
{
std::unordered_map<int,int> mymap;
mymap[100000] = 100 ;
mymap[100001] = 500 ;
mymap[100002] = 500 ;
mymap[100000] = 20 ;
mymap[100000] = 400 ;
mymap[100004] = 1 ;
auto x = mymap.insert( make_pair(100004,100) ) ;
cout << "****" << x.second << "****" << endl ;
if( !x.second){
(x.first)->second = 123456 ;
}
auto y = mymap.insert( make_pair(400004,400) ) ;
cout << "****" << y.second << "****" << endl ;
if( !y.second){
(y.first)->second = 78901 ;
}
for ( auto it = mymap.begin(); it != mymap.end(); ++it )
std::cout << " " << it->first << ":" << it->second;
std::cout << std::endl;
auto got2 = mymap.find(2100000) ;
if(got2 == mymap.end() )
cout << "2100000 not found" << endl ;
else
cout << "2100000 found" << endl ;
auto got = mymap.find(100000) ;
if(got == mymap.end() )
cout << "100000 not found" << endl ;
else
cout << "100000 found:" << got->second << endl ;
}
****0****
****1****
400004:400 100001:500 100002:500 100004:123456 100000:400
2100000 not found
100000 found:400
留言列表