How to make an array of dictionaries in c++ like python?

Question:

so im trying to change my python code to c++ for practice and i just dont know how to make an array of dictionaries in c++.
here is an example of what i want to do:

from numpy import *

E = dict(ch = "", chy = "")
TabE = array([E] * 15)

so i tried to do this but i am getting an error "expected a ‘;’":

std::map<std::string, std::string> E = { {"ch", ""}, {"chy", ""} };
E TabE[15];

is there an alternative to that in c++?

Asked By: Yoshi

||

Answers:

In the C++ code, E is a value, you cannot use it as a type, these are distinct things. If you wanted an array of 15 times of a single array, you can do e.g.:

std::map<std::string, std::string> E = /*...*/;
std::array<std::map<std::string, std::string>, 15> TabE;

for (size_t i = 0; i < 15; ++i) {
    TabE[i] = E;
}
Answered By: lorro
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.