Multidimensional
maps are used when we want to map a value to a combination of keys. The key can be of any data type, including those that are user-defined. Multidimensional maps are nested maps; that is, they map a key to another map, which itself stores combinations of key values with corresponding mapped values.
Syntax:
// Creating a two-dimensional map:
map< key_1_type, map< key_2_type, value_type> > object;
// Creating an N-dimensional map:
map< key_1_type, map< key_2_type, ... map< key_N_type, value_type> > > object;
Example 1:
Output:
First key is 0 And second key is 0 And value is 0
First key is 0 And second key is 1 And value is 1
First key is 1 And second key is 0 And value is 1
First key is 1 And second key is 1 And value is 2
Now accessing map though iterator
First key is 0 And second key is 0 And value is 0
First key is 0 And second key is 1 And value is 1
First key is 1 And second key is 0 And value is 1
First key is 1 And second key is 1 And value is 2
Example 2: