Question

I have this:

std::ofstream * file = new std::ofstream();
if (seperator == 1) file->open("C:/Users/Max/Desktop/Sparade filer/" + name + ".txt");
else 
{
    std::string stamp = (std::string)__DATE__ + " : " + (std::string)__TIME__;
    file->open("C:/Users/*directory*/" + name + " - " + stamp + ".txt");
}

*file << data;
delete file;

*directory* is of course something else

But for some reason, only the things within the if-block works. The filename doesn't exist, so a new file is created completely based on the variables (name is equal to "my save" in this case). So if I set my seperator to 1, I get a new file in my directory called "my file.txt", by which means that it functions properly. However as soon as I set it to something else, I don't get anything. I've checked several times, and the else block is entered, and the first argument of ofstream::open() is a valid string.

Help would be gladly appreciated!

Was it helpful?

Solution

A filename is not allowed to contain character ":".

OTHER TIPS

The DATE and TIME return the time and date the program was compiled. That's different than the system's date and time. Now if that was what you were looking for then great!!

But if you want your program to stamp the folder with the updated system date and time on every run then I recommend looking at this thread. The answer by TrungTN is the works before me.

I hope that helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top