Domanda

I am trying to do something like this using rapidxml using c++

xml_document<> doc; 
ifstream myfile("map.osm"); 
doc.parse<0>(myfile); 

and receive the following error

Multiple markers at this line - Invalid arguments ' Candidates are: void parse(char *) ' - Symbol 'parse' could not be resolved

file size can be up to a few mega bytes.

please help

È stato utile?

Soluzione

You have to load the file into a null terminated char buffer first as specified here in the official documentation.

http://rapidxml.sourceforge.net/manual.html#classrapidxml_1_1xml__document_8338ce6042e7b04d5a42144fb446b69c_18338ce6042e7b04d5a42144fb446b69c

Just read the contents of your file into a char array and use this array to pass to the xml_document::parse() function.

If you are using ifstream, you can use something like the following to read the entire file contents to a buffer

 ifstream file ("test.xml");
 if (file.is_open())
 {
    file.seekg(0,ios::end);
    int size = file.tellg();
    file.seekg(0,ios::beg);

    char* buffer = new char [size];

    file.read (buffer, size);
    file.close();

    // your file should now be in the char buffer - 
    // use this to parse your xml     

    delete[] buffer;
 }

Please note I have not compiled the above code, just writing it from memory, but this is the rough idea. Look at the documentation for ifstream for exact details. This should help you get started anyway.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top