Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ printf和strftime的参数错误无效_C++_Logging - Fatal编程技术网

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。你能手动创建相同的文件吗?试试谷歌搜索“文件名中的冒号”。好的,伙计们,你是对的。不知怎的,我用
忽略了它。谢谢。