mercredi 22 avril 2015

No viable overloaded operator for references a map

I am trying to use a map so I can make tag names to a reference number. When I try and use it, like in this code I get the error (6 in total every time I reference map):

src/main.cpp:25:45: error: no viable overloaded operator[] for type
      'std::map<std::string, std::string>'
                const char* idcs = node.child_value(tagMap[3]);

This is the code:

#include "pugi/pugixml.hpp"

#include <iostream>
#include <string>
#include <map>

int main()
{
    pugi::xml_document doca, docb;
    std::map<std::string, pugi::xml_node> mapa, mapb;
    std::map<std::string, std::string> tagMap {{"1", "data"}, {"2", "entry"}, {"3", "id"}, {"4", "content"}};

    if (!doca.load_file("a.xml") || !docb.load_file("b.xml")) {
        std::cout << "Can't find input files";
        return 1;
    }

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

    for (auto& node: docb.child(tagMap[1]).children(tagMap[2])) {
        const char* idcs = node.child_value(tagMap[3]);
        if (!mapa.erase(idcs)) {
            mapb[idcs] = node;
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire