Can you please tell me how I can write multidimensional map. For two dimensional map, I did the following:
map<string, int> Employees
Employees[“person1”] = 200;
I was trying to use something similar to following for 3d mapping.
map<string, string, int> Employees;
Employees[“person1”, “age”] = 200;
Can you please tell me the correct way to do this?
and Is there a way I can initialize all the map elements to be 0 ? Just like on a array we can say int array[10]={0};
Instead of nested map, you can use tuple as keys; (this is a c++11 code, you could do the same with
boost::tuple
as well).You need to create map of maps like that.
what you are doing here is not 3D mapping but 2D mapping, how to use stl::map as two dimension array
Correct 3D mapping will be like
You can use the
pair
class of theutility
library to combine two objects:See http://www.cplusplus.com/reference/std/utility/pair/