File variable help.

I am trying to substitute a variable for the file directory.

Here is the error:
error: no matching function for call to 'std::basic_ofstream<char>::basic_ofstream(std::string&)'

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <stdio.h>
#include <windows.h>
using namespace std;

class Createc{
public:
string file;

void Createm()
{
file = ("thefile.txt");
ofstream thefile (file);
thefile << "hi" << endl;
thefile.close();
}
};

int main()
{
Createc create;
create.Createm();
}

Please tell me what I am doing wrong
ofstream thefile (file.c_str());

That should fix this issue. std::ofstream wants a const char pointer, not a string. http://www.cplusplus.com/reference/fstream/ofstream/ofstream/
That Works!!

Thank you very much!!
Topic archived. No new replies allowed.