Converting parameters

Hi! Can anyone please tell me how can I make this code work?

Basically it's just a program which creates a file.
1
2
3
4
5
6
FILE * pFile;
string filename;
cout << "Name the project" << endl;
cin >> filename; // This gets the name of the file you want to create. 
pFile = fopen (filename,"w"); // This creates the file, but fails. 
cannot convert parameter 1 from 'std::string' to 'const char *'
fclose (pFile);


What should I do?
Thanks.
Last edited on
you must use the c_str function to get a char pointer:

 
pFile = fopen(filename.c_str(),"w");
Thanks a lot! It works.
Topic archived. No new replies allowed.