just use the []
operator:
std::map<std::string, some_type> my_map;
some_type object=get_object(); // an object that you want to insert into the map
std::string key=get_key(); // the key you want to associated with object
assert(my_map.empty()); // no keys in map yet! (only for demonstration)
my_map[key] = object;
If the map already contains the key provided, than the object for that key is replaced. Otherwise, a new entry into the map is generated and initialised with the object. Read more about std::map
here (and avoid using shared_ptr<>
if you don't know it yet and aren't 200% sure it's needed).