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{
string file;

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

int main()
Createc create;

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.
That Works!!

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