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