mercredi 22 avril 2015

Replace fixed value with a value from a map

So this is a segment of my code:

std::map<int, std:string> tagMap = {{1, "data"},{2,"entry"},{3,"id"}}

....

/* ORIGINAL
for (auto& node: doca.child("data").children("entry")) {
    const char* id = node.child_value("id");
    mapa[id] = node;
}
*/


for (auto& node: doca.child(tagMap.find(1)).children(tagMap.find(2))) {
    const char* id = node.child_value(tagMap.find(3));
    mapa[id] = node;
}

I am trying to replace a fixed definition with one from a map lookup. I wasn't sure quite how to implement this and my approach didn't seem to work. I was wondering if anyone could tell me the right approach to do this please?

Aucun commentaire:

Enregistrer un commentaire