I am doing a simple program that tries to fetch a non-existent key-value pair in the map. But when I run the code, I get a runtime error saying ==8406==WARNING: AddressSanitizer failed to allocate 0x7ffe7f82c881 bytes
==8406==AddressSanitizer's allocator is terminating the process instead of returning 0
==8406==If you don't like this behavior set allocator_may_return_null=1
#include <iostream>
#include <map>
#include <string>
int main ()
{
typedef std::map<std::string,int> mymap;
mymap cnt;
cnt["a"]=10;
auto f = first.find("asdasd");
std::cout << f->second;
return 0;
}
at line where I do f->second
. How could I handle the case where the key does not exist in the map?