C ++ and unorder_map the map

The default value problem of map

Has a default value, the first time value to access a key element, it is inserted into the map, and is initialized to 0;

With erase () to cancel the mapping, that is, delete the key value element

 

map constructor

map<string , int >mapstring;

 

Add map data

maplive.insert(pair<int,string>(102,"aclive"));

 

Find the elements map

find () function returns an iterator to key into key elements, if not found returns an iterator pointing to the tail of the map.       

map<int ,string >::iterator l_it;;
l_it=maplive.find(112);
if(l_it==maplive.end())
cout<<"we do not find 112"<<endl;
else cout<<"wo find 112"<<endl;

 

Delete elements in map

maplive.erase(l_it);

 

Map of the swap is not an element of the container exchange, but the exchange of two containers;

 

Map the elements are automatically sorted in ascending order by key , it can not function map sort by

 

begin () returns a pointer to the head of map iterators
clear () removes all elements
count () returns the number specified element appears
empty () is empty map true if it returns
end () returns a pointer to the end of the map iterators
equal_range () returns iterator particular item to
delete erase () element
find () to find an element
get_allocator () returns the map configurator
insert () element inserted
key_comp () function returns the key element of Comparative
lower_bound () returns the key-value> = a given the first element in a position
MAX_SIZE () returns the maximum number of elements can be accommodated
rbegin () returns a pointer to the tail of the reverse map iterator
rend () returns a pointer to the head of reverse iterator map
size () returns the elements in the map the number of
swap () exchanging two Map
upper_bound, () returns the key> element to the first position of a given
value_comp () function returns the value of the comparison element

 

Guess you like

Origin www.cnblogs.com/sialianzi/p/11425813.html
map
Map
Map
map