Hi, how do I create an unordered map and modify the values? I've tried google, though none of the solutions worked. I'm trying to create a unordered map with all values in a string initialized to 0. Then I want to add 1 for every count of the letter. Any help is appreciated Thanks!
Code:
unordered_map<string, int> letter_count, needle_count;
for (int i = 0; i < H.size(); i++)
{
letter_count.emplace(H[i], 0).first->second = 0;
needle_count.emplace(H[i], 0).first->second = 0;
}
for (int i = 0; i < N.size(); i++)
{
letter_count[H[i]] += 1;
needle_count[H[i]] += 1;
}
Error Given:
error: no match for 'operator[]' (operand types are 'std::unordered_map<std::__cxx11::basic_string<char>, int>' and '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'})|