C++ 连接xmlChar*字符串

C++ 连接xmlChar*字符串,c++,libxml2,string-concatenation,C++,Libxml2,String Concatenation,我正在尝试扭曲xmlChar*字符串,以便将“.rels”附加到文件名上。出于某种原因,我看到了错误: 错误c2440初始化无法从常量字符[6]转换为常量xmlChar* const_cast只能调整类型限定符;它无法更改基础类型 xmlChar是从xmlstring.h libopc/libxml2定义的,因为我知道并不是每个人都知道xmlChar xmlChar * temp = c->part_array[i].name; //this is a filename.doc with

我正在尝试扭曲xmlChar*字符串,以便将“.rels”附加到文件名上。出于某种原因,我看到了错误:

  • 错误c2440初始化无法从常量字符[6]转换为常量xmlChar*
  • const_cast只能调整类型限定符;它无法更改基础类型
  • 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);
    
    但是得到错误:

    错误c2440初始化无法从常量字符[6]转换为常量字符 xmlChar*


    我最终不得不使用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;
    

    直接铸造为我工作:

            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;