c++ - 在 Visual Studio 的哪个版本中引入了函数?

标签 c++ visual-studio

我们有一个在 Visual Studio 2003.NET 中构建的旧项目。仍然工作正常,但我们正在将其迁移到 Visual Studio 2019。令人惊讶的是,到目前为止,问题很少,但有很多警告。一个警告与 fopen 相关:

warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.

在 VS2019 中将其转换为 fopen_s 很简单,但这不会在 Visual Studio 2003.NET 中构建(因为 fopen_s 不是可识别的关键字)。这可以通过如下代码解决:

#if (_MSC_VER <= 1310)
        // Visual Studio 2003.NET or earlier
        FILE* fp = fopen(pszTXT, "w");
#elif (_MSC_VER > 1310)
        // Newer versions of Visual Studio
        FILE* fp = NULL;
        fopen_s(&fp, pszTXT, "w");
#endif

fopen_s 何时引入 Visual Studio? MSDN link目前尚不清楚。

这个问题是一般性的,而不是特定于 fopen_s => 是否有文档显示引入(或废弃)关键字或方法的 Visual Studio 版本。

最佳答案

来自Visual C++ What's New 2003 through 2015 _s 函数是在 2005 版本中添加的。

New CRT Features

  • Secure versions of several functions have been added. These functions handle errors in a better way and enforce stricter controls on buffers to help avoid common security flaws. The new secure versions are identified by the _s suffix.
<小时/>

对于 C++ 功能和更改支持,您可以查看 cppreferences C++ compiler support查看哪个编译器版本支持特定的 C++ 功能。这不适用于 _s 函数,因为它们是 C 功能,而不是 C++。

关于c++ - 在 Visual Studio 的哪个版本中引入了函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60490102/

相关文章:

c++ - 用 c 编写并从 cpp 文件调用的 dll 文件中函数的预期行为

c++ - Lambda 适用于最新的 Visual Studio,但在其他地方不起作用

c# - Visual Studio : Automatically insert a space after typing if(

c - 在 Visual Studio 中设置 FILE_ATTRIBUTE_DEVICE

c++ - 是否有用于 Visual Studio 的工具来跟踪(或中断)变量值?

visual-studio - 在VS2015 RC上添加Native Tools命令提示符

c++ - 是否存在 self 分配有用的情况?

c++ - 模板参数中未命名的类/类型名

c++ - C++ 中的空指针

c++ - 如何按值对 STL 映射进行排序?