TinyXML #include 问题...使用库
嘿,我真的想让 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是你的问题。
dump_to_stdout
采用const char*
,而 TiXmlDocument 绝对不是。dump_to_stdout
就是您所在的那个,因此会出现错误。在该函数之前向前声明您想要的函数,例如:void dump_to_stdout(TiXmlDocument*);
Here's your problem.
dump_to_stdout
takes aconst char*
which TiXmlDocument is definitely not.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*);
TiXmlDocument
,而不是TiXMLDocument
dump_to_stdout
的未声明重载,编译器假定您想要调用采用const char *
的版本,但失败了。TiXmlDocument
, notTiXMLDocument
dump_to_stdout
, the compiler assumes you want to call the version that takesconst char *
and fails.