TinyXML #include 问题...使用库

发布于 2024-10-13 23:55:24 字数 1044 浏览 5 评论 0原文

嘿,我真的想让 TinyXML 至少读取一个文件,但它说“main.cpp:8:错误:'TiXMLDocument'未在此范围内声明”

这是我使用的代码:

TiXMLDocument("demo.xml");

理想情况下我想阅读能够读取文件并输出 XML,所以我也尝试了我在教程中在线找到的这段代码

#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;
}

,我现在遇到的错误是:

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*)’

如果它对 Mac 上的我有帮助,我尝试在终端和 textmate 中进行编译。我还尝试在编译 main.cpp 之前单独编译 TinyXML 的 cpp 文件,但我不知道为什么我无法打印出 demo.xml,更不用说读取它了。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你是暖光i 2024-10-20 23:55:24
dump_to_stdout( &doc ); // defined later in the tutorial

这是你的问题。

  1. dump_to_stdout 采用 const char*,而 TiXmlDocument 绝对不是。
  2. 您已经在该函数中,因此假设文件加载,您将拥有无限递归。
  3. 稍后定义一个采用 TiXmlDocument 的文件并不重要。此时,唯一存在的 dump_to_stdout 就是您所在的那个,因此会出现错误。在该函数之前向前声明您想要的函数,例如:void dump_to_stdout(TiXmlDocument*);
dump_to_stdout( &doc ); // defined later in the tutorial

Here's your problem.

  1. dump_to_stdout takes a const char* which TiXmlDocument is definitely not.
  2. You're already in that function, so assuming the file loads you'll have infinite recursion.
  3. It doesn't matter that you've got one defined later that takes a TiXmlDocument. At this point, the only dump_to_stdout that exists is the one you're in, hence the error. Forward declare the one you want before this function, e.g: void dump_to_stdout(TiXmlDocument*);
凉薄对峙 2024-10-20 23:55:24
  1. 它称为 TiXmlDocument,而不是 TiXMLDocument
  2. 您不能调用尚未声明的函数。由于您尝试调用 dump_to_stdout 的未声明重载,编译器假定您想要调用采用 const char * 的版本,但失败了。
  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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文