【问题标题】:ERROR in c++ program using Libxml2 [duplicate]使用 Libxml2 的 C++ 程序中的错误 [重复]
【发布时间】:2014-04-11 13:20:38
【问题描述】:

这是我的 c++ 问题,我有错误,请帮助我:/

我想看d:

<svg>
    <g>
       <path ***d***="11"/>
    </g>
</svg>

但我的程序不工作:/

how to read a part of xml file in C++ using Libxml2

我的答案中的代码,UP

错误:

/home/praktyka/projects/svgreader/main.cpp:83:38:错误:从“const char*”到“const xmlChar* {aka const unsigned char*}”的无效转换 [-fpermissive]

/usr/include/libxml/tree.h:1021:3: 错误:正在初始化‘xmlChar* xmlGetProp(xmlNodePtr, const xmlChar*)’的参数 2 [-fpermissive]

【问题讨论】:

标签: c++ xml


【解决方案1】:

来自here [刚刚谷歌搜索]

xmlChar 似乎是unsigned char 的类型定义。然而,文字字符串是 const char *... 因此,您需要将您的行修改为:

if(xmlGetProp(cur_node, (const xmlChar *)"d")) 

为了安全起见(xmlChar 是 UTF8...您的字符串可能有所不同)...考虑查看 libXML2 中的相关函数,例如xmlCharStrdup

【讨论】:

  • 好的,谢谢编译但是当我想启动程序时出现“分段错误”错误
  • @user3520459 尝试在调试器中运行它。分段错误发生在哪里?
  • 我需要使用带有“cc -o main -I /usr/include/libxml/main.cpp -lxml2”命令的终端,当我启动“./main”时出现错误
  • @Rafael 不确定你有什么样的系统(看起来像某种 unix),检查你是否有可用的 gdb。运行 gdb ./main 并在 gdb 提示符下运行:run
  • 当我使用 gdb 时出现“程序收到信号 SIGSEGV,分段错误。0x0000000000400c47 in main ()”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多