连接xmlChar *字符串

时间:2014-11-12 14:09:55

标签: c++ libxml2 string-concatenation

我试图连接xmlChar *字符串以附加" .rels"到文件名。出于某种原因,我看到了错误:

  
      
  1. 错误c2440初始化无法从const char [6]转换为const xmlChar *。
  2.   
  3. const_cast只能调整类型限定符;它无法改变基础类型。
  4.   

xmlChar是从xmlstring.h,libopc / libxml2定义的,因为我知道不是每个人都知道xmlChar。

xmlChar * temp = c->part_array[i].name; //this is a filename.doc with  path, has no compile error
                const xmlChar* temp2 = const_cast<xmlChar*>(".rels"); //"rels" here has error
                xmlStrcat(temp, temp2);

xmlStrcat需要xmlStrcat(xmlChar * cur,const xmlChar * add),我认为我有这个,一旦我让temp2快乐。

有什么想法吗?我在查找xmlChar *示例时遇到了问题。我尝试使用:

const xmlChar* temp2 = ".rels";

但得到错误:

  

错误c2440初始化无法从const char [6]转换为const   XMLCHAR *

2 个答案:

答案 0 :(得分:0)

我不得不使用xmlStrndup和xmlCharStrndup

        xmlChar * temp = xmlStrndup(c->part_array[i].name, max_part_name);
        const char* tempA = ".rels";
        xmlChar* temp2 = xmlCharStrndup(tempA, sizeof(tempA));
        xmlStrcat(temp, temp2);
        const xmlChar* temp3 = (const xmlChar*)temp;

答案 1 :(得分:0)

直接投射对我有用:

enter image description here

相关问题