printf 和 strftime 的参数错误无效
Invalid argument error with printf and strftime
假设我有一个程序将某些内容写入日志文件。一切正常,直到我决定在文件名中添加时间戳。
这是我这样做的方法:
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");
我不知道为什么,但fopen
返回NULL
.
filename
没关系:20-08-2017_01:08:09.txt
,但是如果我将文件名更改为logfile.txt
例如 - 一切都可以正常工作。
就好像文件名中不允许某些字符,但我用-
、_
、:
对其进行了测试,事实并非如此。
有人有什么想法吗?
尝试转义 : 字符,这可能是问题所在
相关文章:
- 错误:无效的预处理指令 #i 的意思是 #if?
- is_same和variadic模板编译时错误无效转换
- printf 和 strftime 的参数错误无效
- 错误:无效使用非静态成员函数"int test::hotplug_callback(libusb_contex
- 我收到一个错误无效的操作数,类型为 const char [42] 和二进制"运算符+"的双倍数
- 错误:无效使用无效
- 发布信号量返回错误 6(无效句柄)
- C++17 可选树,错误:无效使用不完整的类型
- C++ 线程函数指针实现返回错误无效使用非静态成员函数
- 在测试中使用unique_ptr时指针错误无效
- 使用 malloc 而不是 new 会导致 free():指针错误无效
- valgrind错误无效读数4
- X11 XGetImage badmatch错误(无效的参数属性)
- free():C++中的指针错误无效
- 使用 valgrind 的地图中的读取大小错误无效
- 错误:无效的基类C
- 错误:无效使用了void表达式C++
- C++链接错误.无效
- free()错误:无效的下一个大小(fast)
- 我收到错误"无效使用不完整的类型'class map'