C++:使用String作为函数参数的麻烦

Bio*_*i3c 0 c++ arguments const function char

好的,我在使用以下代码时遇到问题(在头文件中):

#ifndef XML_H_INCLUDED
#define XML_H_INCLUDED
#include "libxml/parser.h"
#include "libxml/xmlwriter.h"
#include <string>


class XmlFile{
public:
    XmlFile(string filename){
        file = xmlParseFile(filename);


    }
    xmlDocPtr file; //Pointer to xml file


};



#endif // XML_H_INCLUDED
Run Code Online (Sandbox Code Playgroud)

该文件包含在主源文件中(但不被访问,因此其内容并不重要).

我一直收到以下错误(在Codeblocks中):

error: cannot convert 'std::string' to 'const char*' 
for argument '1' to 'xmlDoc* xmlParseFile(const char*)'|
Run Code Online (Sandbox Code Playgroud)

我遇到过这么多次,这让我发疯了.

如果可能的话,我宁愿不使用向量(在初始化函数时增加了另一个步骤.

我究竟做错了什么?我试过这个,但没有找到任何满意的答案.

提前致谢.

ima*_*boy 6

file = xmlParseFile(filename.c_str());
Run Code Online (Sandbox Code Playgroud)