FSTREAM不创建具有附加到文件名的ASCTIME值的文件

fstream not creating a file with a asctime value appened to the file name

本文关键字:文件名 ASCTIME 文件 创建 FSTREAM      更新时间:2023-10-16

我已经对此进行了调试,直到我知道这个问题,我只是不知道如何解决。

现在我正在使用:

file.open(logFile.c_str(), std::ios::out | std::ios::app); 

只要我评论以下标记的行:

time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
timeinfo = localtime (&rawtime);
logFile = "bin/";
if(_DEBUG) { logFile += "Debug/"; }
else { logFile += "Release/"; }
logFile += fileName;
if(_DEBUG) { logFile += "Debug-"; }
else { logFile += "Release-"; }
logFile += asctime(timeinfo); // Works fine with this line commented.
logFile += ".log";

那么,我该如何使此行正确使用?

至少对于ntfs而言,结肠(:)是文件名的非法字符。尝试使用strftime()而不是格式化一个不包含结肠的字符串。

我会猜测。例如,将时间添加到您的文件名中,例如12:23:34。我猜您正在使用文件名中使用结肠不合法的文件系统。

解决方案(如果我的猜测是正确的话),请用下划线或类似。