如何在不首先创建和定义具有结构类型的实际对象的情况下将数据添加到包含 int 键和结构值的映射?基本上我有:
struct myStruct { string name2; int aCnt; std::list<string> theItems; };
// Now I define a map
std::map<string, myStruct> myMap;
// Now I want to add items to myMap.
mymap["ONE"] = {"TEN", 3, {"p1","p2","p3"}}; // But this doesn't seem to work
// I know I could do something like
myStruct myst;
myst.name2 = "TEN";
myst.aCnt = 3;
...blah blah
mymap["ONE"] = myst;
// But I don't want to have to write all of those lines especially because
// this is being done as an initialization of the map.
谢谢!