Writing files with no defined directory

hi, I am new to C++ but have programmed in C# and java before. so far i get the basics of C++.

my problem is when i want to write a file use;
#include <fstream>

void main()
{
ofstream ofs("file.txt");
//so on so forth.
}

what i want to be able to do is something like:

string fileLoc;
cin >> fileLoc;
ofstream(fileLoc);
//and again...

problem is that ofstream takes a const *char (I think? -pointers like this are new to me-).

is there anyway to achieve this preferably without using something too platform dependant.

thanks for your time.
string fileLoc;
cin >> fileLoc;
ofstream ofs(fileLoc.c_str());

That should do it.

http://www.cplusplus.com/reference/string/string/c_str/
great thanks. (there will be more questions to follow :D)
Topic archived. No new replies allowed.