I am trying to see if a particular key exists in map and if so then I want to increase its value by 1. But while running the program I am getting the error
terminate called after throwing an instance of 'std::out_of_range' what(): map::at
Why is it going out_of_range can someone help?
b is a map in this function. itr is an iterator for accessing its elements
for(int i=0;i<n;i++)
{
        ct=0;
        cin>>a[i];
        for(itr=b.begin();itr!=b.end();itr++)
        {
            if(itr->first==a[i])
                ct++;
            else
                continue;
        }
        if(!ct)
        {
            b.at(a[i])++;
        }
        else
        {
            b.insert(pair <int,int>(a[i],1));
        }
    }
}
 
     
    