开发者

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

开发者 https://www.devze.com 2023-01-17 09:33 出处:网络
Okay, I am having trouble with the following piece of code (in a header file): #ifndef XML_H_INCLUDED #define XML_H_INCLUDED

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*' 
fo开发者_JAVA技巧r 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());
0

精彩评论

暂无评论...
验证码 换一张
取 消