Accessing values in an unordered_map

I have the following code that checks the value of each key in an unordered_map called char_count, and returns false if we find a value that is not equal to zero:

1
2
3
4
for(auto i:char_count){
    if(char_count[i] != 0){
        return false;
}


Unfortunately this gives the following error: no match for 'operator[]' (operand types are 'std::unordered_map<char, int>' and 'std::pair<const char, int>').

I've also tried the following:

1
2
3
4
for(int i = 0; i < char_count.size(); i++){
    if(char_count->second != 0){
        return false;
}


but get the follwing error: base operand of '->' has non-pointer type 'std::unordered_map<char, int>'

Any help would be much appreciated.
Last edited on
1
2
3
4
for(auto i:char_count){
    if(i.second != 0){
        return false;
}
Topic archived. No new replies allowed.