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 :
This is the fileTime() function :Code:dateTimeName = fileTime();
This trys to name the output file with the date and time.Code:string fileTime() { time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); return (asctime (timeinfo)); }
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.Code:outf = dateTimeName; ofstream outFile(outf.c_str());
What do i need to do to get it to work ?



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.