map::count function


The map::count function count the number of elements having the same specified key.

size_t count(const key_type& x) const;

key_type : A type of the key in the pair element.

Link: key_type of pair

Parameters:
x -A key to be located.

Return type
size_t -Number of elements with the given key.

This function make sense only for multimap container which allows duplicate key.In map this function returned value is either 1 or 0.1 when the key is found and 0 when no key is found.

Code example

map<int,string> mp{{12 , “Twelve”} , {34 , “Thrity-four”} , {9, “nine”} , {54 , “fifty-four”}};

cout<< mp.count(12) <&lt endl
<< mp.count(30) ;

Output

1
0


 


Stop wasting time,earn money($$$) from your website-Join Now!