Browse - Programming Tips - What happens when a key is missing from a std::map ?
Q. What happens when a key is missing from a std::map<> ?
A. It makes an empty entry then gives that to you.
If we have:
std::map<std::string, std::string> fruit;
fruit["apple"] = "red";
fruit["bannana"] = "yellow";
Then we try to get:
std::string c = fruit["orange"];
String c will be "". Since its been added to the map.
Note this as changed fruit.size()
You can use fruit.find("orange") to see if a key is present.