c++ - No viable overloaded operator for references a map -


i trying use map can make tag names reference number. when try , use it, in code error (6 in total every time reference map):

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

this 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;     }      (auto& node: doca.child(tagmap[1]).children(tagmap[2])) {         const char* id = node.child_value(tagmap[3]);         mapa[id] = node;     }      (auto& node: docb.child(tagmap[1]).children(tagmap[2])) {         const char* idcs = node.child_value(tagmap[3]);         if (!mapa.erase(idcs)) {             mapb[idcs] = node;         }     } } 

const char* idcs = node.child_value(tagmap[3]); 

is incorrect, tagmap can indexed keytype std::string need is:

const std::string& idcs = node.child_value(tagmap["3"]); 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -