Here is my code when I am learning the function of count in map .
#include <iostream><br />#include <map><br />using namespace std;</p><p>typedef pair<int,int> pa;<br />typedef map<int,int> ma;</p><p>typedef pair<pa,int> paa;<br />typedef map<pa,int> maa;</p><p>int main()<br />{<br />ma m;<br />m.insert(pa(1,2));<br />m.insert(pa(2,1));</p><p>//keys must be unique in map , so duplicates are ignored<br />cout<<"The number of elements in m with a sort key of 1 is: "<<m.count(1)<<endl;<br />cout<<"The number of elements in m with a sort key of 2 is: "<<m.count(2)<<endl;<br />cout<<"The number of elements in m with a sort key of 3 is: "<<m.count(3)<<endl;</p><p>cout<<endl;</p><p> //some complex usage , it is very useful when you write memory search<br />maa mm;<br />mm.insert(paa(pa(1,1),1));<br />mm.insert(paa(pa(2,2),2));<br />mm.insert(paa(pa(1,2),1));</p><p>cout<<"The number of elements in m with a sort key of (1,1) is: "<<mm.count(pa(1,1))<<endl;<br />cout<<"The number of elements in m with a sort key of (2,2) is: "<<mm.count(pa(2,2))<<endl;<br />cout<<"The number of elements in m with a sort key of (1,2) is: "<<mm.count(pa(2,1))<<endl;</p><p>}<br />/*<br />The number of elements in m with a sort key of 1 is: 1<br />The number of elements in m with a sort key of 2 is: 1<br />The number of elements in m with a sort key of 3 is: 0</p><p>The number of elements in m with a sort key of (1,1) is: 1<br />The number of elements in m with a sort key of (2,2) is: 1<br />The number of elements in m with a sort key of (1,2) is: 0<br />Press any key to continue<br />*/