gpt4 book ai didi

c++ - TinyXml 解析器拒绝正确加载文件

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:57:49 28 4
gpt4 key购买 nike

我有以下 xml 文件:

<?xml version="1.0" ?>
<Hello>World</Hello>

它与我所有其他文件位于同一目录中。

然后我用这个源文件的方法来解析它:

void Character::assign_xml(const char * filename) //Assign xml takes the name of the xml file as a string, and uses it to parse the file's nodes.
{
TiXmlDocument * doc = new TiXmlDocument(filename);

bool loadOkay = doc->LoadFile(filename);



if (loadOkay)
{
printf("\n%s\n", filename);
}
else
{
printf("%s does not work.", filename);
}

delete doc;

}

然而,当我将字符串传递给它时,我的 loadOkay 变量等于 false。这是为什么?

我的输出结果如下:

Starting /home/holland/code/qt/chronos-build-desktop/chronos...
id01.xml does not work.Failed to open file/home/holland/code/qt/chronos-build-desktop/chronos exited with code 0

strace 提供的地方:

futex(0x84579c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
open("id01.xml", O_RDONLY) = -1 ENOENT (No such file or directory)
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb773e000
write(1, "id01.xml does not work.Failed to"..., 42id01.xml does not work.Failed to open file) = 42

最佳答案

您不应将文件名同时传递给文档构造函数和 LoadFile()。根据 TinyXML 网站上的示例,尝试从后者中省略它。

如果还是不行,打印出 doc->ErrorDesc()(可能还有 ErrorRow 和 ErrorCol)。

并阅读文档:http://www.grinninglizard.com/tinyxmldocs/classTiXmlDocument.html

关于c++ - TinyXml 解析器拒绝正确加载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7183798/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com