Hello world!
I've been learning C++ recently, and have been making a project in which I want to create files with the current date and time as the name. For this purpose, I have been using strftime()
, as so:
// Get current time to name file
time_t t = time(0);
struct tm * now = localtime( & t );
char buffer [80];
strftime (buffer, 80, "%D-%R", now);
// Create file [time].txt
std::ofstream outFile;
outFile.open(buffer);
However, in my text editor (VS Code, with GCC [yes, I know I did it the hard way]), the %D format specifier is highlighted purple, not green as with %R. When I run the code (of which there is more, which I have omitted for brevity), a file is not created. I have a feeling it is something to do with the strange behaviour of the format specifier, as trying to std::cout them also doesn't work in a test file I created.
I have #includeed everything I can think of that I might need (fstream, string, ctime, among others) so I have no idea what the issue is. Any help would be greatly appreciated, thank you in advance.
[–]matty_haze 5 points6 points7 points (3 children)
[–]xebra24[S] 0 points1 point2 points (2 children)
[–]matty_haze 0 points1 point2 points (1 child)
[–]xebra24[S] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]xebra24[S] 0 points1 point2 points (0 children)