Reputation: 379
I have following map declaration :
std::map<std::string, std::map<std::string, std::map<std::string, std::string>>> m;
I tried inserting data in following way :
m.insert({ "HARDWARE\\DESCRIPTION\\System\\BIOS", { "REG_SZ", { "SystemSKU", "SystemSKU" } } });
but its not working , what is correct syntax to insert data?
Upvotes: 1
Views: 67
Reputation: 13934
This list initialization will work for you:
std::map<std::string, std::map<std::string, std::map<std::string, std::string>>> m{{"HARDWARE\\DESCRIPTION\\System\\BIOS",
{{ "REG_SZ", {{ "SystemSKU", "SystemSKU" }} }}
}};
Or, use insert
m.insert({"HARDWARE\\DESCRIPTION\\System\\BIOS",
{{ "REG_SZ", {{ "SystemSKU", "SystemSKU" }} }} //create inner maps using double braces
});
It uses std::map's list constructor (the one that takes a std::initializer_list>).
It is little tricky to read and write though.
Note that the double braces {{ or }} are used together. Inner ones {} marks the single entry in a map, and outer one {} represents the map as a whole.
Liked other answer for simplicity.
Upvotes: 0
Reputation: 101
If you cannot get it to work with initializer lists you could use the classical way:
m["HARDWARE\\DESCRIPTION\\System\\BIOS"]["REG_SZ"]["SystemSKU"] = "SystemSKU";
Hope this helps.
Upvotes: 4