Good luck, I see that with the array I can do this:
int array[]= {5,6,4,2};
My question is, in the language C ++ I can declare the map already passing values?
Example:
map<string,int> mymap = { "a",1};
Good luck, I see that with the array I can do this:
int array[]= {5,6,4,2};
My question is, in the language C ++ I can declare the map already passing values?
Example:
map<string,int> mymap = { "a",1};
In fact, your initialization example for map
was {}
to be right!
Just enough:
map<string,int> mymap = {{"a",1}};
// ^ ^
The question is what the first pair of {}
represents the map
integer and then takes other {}
for each initialized element.
So if you wanted to boot with more elements could do:
map<string,int> mymap = {{"a",1}, {"b",2}, {"c",3}};
It's worth mentioning that the support is from C ++ 11