Insert unordered_map into a vector

I need a vector in which i want to insert std::unordered_map.

let, std::unordered_map<int,boost::gregorian::date>un_map;
std::vector<std::unordered_map<int,boost::gregorian::date>>main_vec;

My question is: How to insert and access elements of that vector?

Thanks in advance.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>

int main()
{
    std::vector<std::unordered_map<int,std::string>>main_vec(10); // ten maps in the vector
    
    main_vec[0].insert({1,"Beans"});
    main_vec[0].insert({2,"Kittens"});  
    
    main_vec[1].insert({1,"Blue"});
    main_vec[2].insert({2,"Green"});    
    
    std::cout << main_vec[0][1] << ' ' << main_vec[1][1];
}

Do you want to insert the whole map into the vector or only the values ?
Topic archived. No new replies allowed.