Automatically dating an output file created by ofstream
I am trying to create a program that stores some data in a file then closes it. I need the file to be named with the date and time of when it was closed by the program. I am using ofstream to write the file out and I am using a string variable that has the date in it.
This calls my function that gets the time and date from the computer and stores it in a variable :
Code:
dateTimeName = fileTime();
This is the fileTime() function :
Code:
string fileTime()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
return (asctime (timeinfo));
}
This trys to name the output file with the date and time.
Code:
outf = dateTimeName;
ofstream outFile(outf.c_str());
The trouble is it just refuses to work, if I give it an actual static string such as "test.txt" it will work fine but if I give it a variable which is a string it wont create the file.
What do i need to do to get it to work ?