- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下 C++ 代码无法使用 VS2015 进行编译:
#include <time.h>
#include <ctime>
void main()
{
const time_t t = std::time(nullptr);
std::tm tm = {};
std::localtime_s(&tm, &time);
}
错误信息是:
Microsoft (R) C/C++ 优化编译器版本 19.00.24215.1 for x86版权所有 (C) Microsoft Corporation。保留所有权利。
t.cppt.cpp(10): error C2039: 'localtime_s': 不是 'std' 的成员C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\ctime(17):注意:参见“std”声明t.cpp(10): error C2664: 'errno_t localtime_s(tm *const ,const time_t *const )': 无法将参数 2 从 'time_t (__cdecl *)(time_t *const )' 转换为 'const time_t *const 't.cpp(10): 注意:没有上下文可以进行这种转换
有什么解决方法? (使用 std::localtime() 不是一个选项)。
最佳答案
根据 [headers]/10
Annex K of the C standard describes a large number of functions, with associated types and macros, which “promote safer, more secure programming” than many of the traditional C library functions. The names of the functions have a suffix of _s; most of them provide the same service as the C library function with the unsuffixed name, but generally take an additional argument whose value is the size of the result array. If any C++ header is included, it is implementation-defined whether any of these names is declared in the global namespace. (None of them is declared in namespace std.)
强调我的
和表 18 将 localtime_s
列为成员,因此,由于上面的部分,我们知道它没有在命名空间 std
中定义,如果它确实存在,它将在全局命名空间中。尝试使用
::localtime_s(&tm, &time);
如果仍然不起作用,则表示您的实现不支持它。
关于c++ - 'localtime_s' : is not a member of 'std' in VS2015,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50988689/
我是一名优秀的程序员,十分优秀!