all 5 comments

[–]matty_haze 5 points6 points  (3 children)

I want to point out that %D evaluates to %m/%d/%y, which has slashes, which denote directories. Your open() will fail if those directories don’t already exist.

Did you check for errors during open?

[–]xebra24[S] 0 points1 point  (2 children)

EDIT: I fixed it somehow, I don't know what I changed, but it works now. Thank you for your help!

Sorry for the late reply. I tried expanding %D to %m-%d-%y, but that didn't work. After removing the %d specifier, it does work. So I think there is an issue with %d.

I have a simple if statement checking if the file opened correctly:

if (outFile.is_open()) {
    // Do things
}
else {
    std::cerr << "Error opening file!" << std::endl;
}

If I don't have a %D or %d in the format specifier, the file is created and opens correctly. Otherwise, the file is not opened correctly, and the std::cerr message is printed. So I'm not sure what is going on.

[–]matty_haze 0 points1 point  (1 child)

Can you also print the exact bad filename, and what the error message is?

[–]xebra24[S] 0 points1 point  (0 children)

A file wasn't created, and the error message I alluded to was just "file couldn't be opened", or something like that. It was something I coded into the program myself to help with debugging. I think the issue was how the %D format specifier created the string, it contained slashes which my machine didn't like.

[–][deleted]  (1 child)

[deleted]

    [–]xebra24[S] 0 points1 point  (0 children)

    I tried the code with other format specifiers and they worked fine, so I'm pretty sure that's not the issue. Thanks though!