C++ printf和strftime的参数错误无效
比如说,我有一个程序,可以将一些东西写入日志文件。在我决定给文件名添加时间戳之前,一切都很顺利 我是这样做的:C++ printf和strftime的参数错误无效,c++,logging,C++,Logging,比如说,我有一个程序,可以将一些东西写入日志文件。在我决定给文件名添加时间戳之前,一切都很顺利 我是这样做的: time_t rawtime; struct tm * timeinfo; char buffer[80]; time(&rawtime); timeinfo = localtime(&rawtime); strftime(buffer, sizeof(buffer), "%d-%m-%Y_%I:%M:%S_", timeinfo); std::string time
time_t rawtime;
struct tm * timeinfo;
char buffer[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, sizeof(buffer), "%d-%m-%Y_%I:%M:%S_", timeinfo);
std::string timestring(buffer);
std::string filename = timestring + ".txt";
std::cout << "\n" << filename << std::endl;
FILE *f = fopen(filename.c_str(), "w");
time\u t rawtime;
结构tm*时间信息;
字符缓冲区[80];
时间(&rawtime);
timeinfo=localtime(&rawtime);
strftime(buffer,sizeof(buffer),%d-%m-%Y\%I:%m:%S\',timeinfo);
std::字符串时间字符串(缓冲区);
std::string filename=timestring+“.txt”;
std::cout尝试转义:字符,这可能是问题所在什么操作系统?如果是Windows,则似乎不允许使用:
。你确定测试正确吗?Win 8.1,VS2015,Intel Compiler 17.0。你能手动创建相同的文件吗?试试谷歌搜索“文件名中的冒号”。好的,伙计们,你是对的。不知怎的,我用:
忽略了它。谢谢。