为什么 Visual Studio 2013 在 C4996 上出错?

2021-12-31 00:00:00 visual-studio c++ visual-studio-2013

在以前版本的 Visual Studio 中,使用 _sleep 或 strncpy 等函数只会输出警告.最新版本,突然报错:

In previous versions of Visual Studio using functions like _sleep or strncpy just outputs a warning. In the latest version, it's suddenly an error:

错误 C4996:'_sleep':此函数或变量已被取代通过更新的库或操作系统功能.考虑使用睡吧.有关详细信息,请参阅在线帮助.

error C4996: '_sleep': This function or variable has been superseded by newer library or operating system functionality. Consider using Sleep instead. See online help for details.

我知道我可以通过在代码的开头添加 #pragma warning(disable: 4996) 来禁用它,但是非常烦人的是 VS 试图强迫我使用其他功能.有什么办法可以禁用这种行为吗?

I know I can disable it by adding #pragma warning(disable: 4996) in the beginning of the code, but it's extremely annoying that VS is trying to force me to use other functions. Is there any way to disable this behavior?

在您询问之前,将警告视为错误"已禁用,即使我关闭所有警告,它也会出错!

Before you ask, "Treat Warnings As Errors" is disabled, and it errors even if I turn off all warnings!

推荐答案

显然新项目现在默认启用SDK 检查",将这些警告视为错误.要禁用它,请转到项目属性 -> 配置属性 -> C/C++ -> 常规 -> SDL 检查 -> 否.

Apparently new projects enable "SDK check" by default now, which treats these warnings as errors. To disable it, go to project properties -> Configuration Properties -> C/C++ -> General -> SDL checks -> No.

相关文章