jeudi 4 novembre 2021

How to add data to a std::map of std::strings and std::vectors

This looks more tricky than I thought. Lets say I have a std::map of std::vectorstd::string like below

std::map<std::string, std::vector<std::string>> my_map_2;

So, the key of my_map_2 is a std::string but the value field is a std::vector which needs to be added with more entries.

How do I add data to it? I want to add like 3 entries to the map with each of the entries containing 2 example strings

std::string str_1 = "key_1";
std::string str_2 = "value_1";
my_map_1.insert(std::make_pair(str_1, str_2));  // This does not work!

Aucun commentaire:

Enregistrer un commentaire