0

In Visual Studio C++, I am trying to write a file with the current datetime as the file name.

time_t now = time(0);
char* dt = ctime(&now);

char filename[] = "DateTime.txt";

fstream newfile(filename, std::fstream::in | std::fstream::out | std::fstream::app);

if (newfile.is_open())
{
    newfile << dt;
    newfile.close();
}

I need to either convert dt to a char array, remove the ":" in the time and add the file extension or find an alternative method.

Thanks

0 Answers0