简体   繁体   中英

C++: Trouble Using String as Argument of a Function

Okay, I am having trouble with the following piece of code (in a header file):

#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

The file is including in the main source file (but is not accessed, so its contents are not important).

I keep getting the following error (In Codeblocks):

error: cannot convert 'std::string' to 'const char*' 
for argument '1' to 'xmlDoc* xmlParseFile(const char*)'|

I have run into this many times, and it is driving me crazy.

I would prefer not to use vectors if possible (adds another step in initializing the function.

What am I doing wrong? I've tried looking this up, but have not found any satisfactory answers.

Thanks in advance.

file = xmlParseFile(filename.c_str());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM