c++terminaltextmatelibrariestinyxml

TinyXML #include problem... Using libraries


Hey, i'm really trying to get TinyXML to at least read a file but it says "main.cpp:8: error: ‘TiXMLDocument’ was not declared in this scope"

This is the code im using:

TiXMLDocument("demo.xml");

Ideally i want to read able to read files and output the XML so i also tried this code i found online in a tutorial

#include <iostream>

#include "tinyxml.h"
#include "tinystr.h"

void dump_to_stdout(const char* pFilename)
{
    TiXmlDocument doc(pFilename);
    bool loadOkay = doc.LoadFile();
    if (loadOkay)
    {
        printf("\n%s:\n", pFilename);
        dump_to_stdout( &doc ); // defined later in the tutorial
    }
    else
    {
        printf("Failed to load file \"%s\"\n", pFilename);
    }
}

int main(void)
{
    dump_to_stdout("demo.xml");
    return 0;
}

And the errors I'm getting now are:

main.cpp: In function ‘void dump_to_stdout(const char*)’:
main.cpp:13: error: cannot convert ‘TiXmlDocument*’ to ‘const char*’ for argument ‘1’ to ‘void dump_to_stdout(const char*)’

If it helps im on a mac, ive tried compiling in terminal as well as textmate. I also tried to compile the cpp files for TinyXML separately before compiling main.cpp and i have no idea why i cant print out demo.xml let alone read it.


Solution

    1. It's called TiXmlDocument, not TiXMLDocument
    2. You can't call a function that you haven't declared yet. Since you're trying to call an undeclared overload of dump_to_stdout, the compiler assumes you want to call the version that takes const char * and fails.