-3

I have recently been trying to use TinyXML2 to read/write XML files, but I encountered a problem. I am trying to read a integer array that I exported from another program and it loads but TinyXML won't read integer arrays and I can't convert constant characters pointers to integers.

I want to separate comma separated values and store them in a array.

My code is as follows.

    int GetMapData (const char* XMLFile) {
        int mapdata[1];
        XMLDocument File;
        File.LoadFile(XMLFile);
        const char* data = File.FirstChildElement("map")->FirstChildElement("layer")->FirstChildElement("data")->GetText();
}

1 Answers1

1

update with commas

#include <sstream>

// ... 

char const *ss = "1, 2, 3, 4";  // this come from the FirstChildElement method in your case.
istringstream buffer(ss);
int value1, value2, value3, value4;
char c;
buffer >> value1 >> c >> value2 >> c >> value3 >> c >> value4;
cout << value1 << "-" << value2 << "-" << value3 << "-" << value4  << endl;

output: 
1-2-3-4

are you looking for something like this?

of course you have to polish it, but It should give the idea. Kasper

Kasper
  • 599
  • 1
  • 7
  • 26