Why does Visual Studio 2013 error on C4996?

后端 未结 6 1622
半阙折子戏
半阙折子戏 2020-12-01 04:35

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:

相关标签:
6条回答
  • 2020-12-01 04:35

    Compiling all sources I have referred:

    Remove secure warnings (_CRT_SECURE_NO_WARNINGS) from projects by default in Visual Studio

    kmcnamee's answer on How to use use _CRT_SECURE_NO_WARNINGS

    Video that solved my problem. https://www.youtube.com/watch?v=qWxGZLjwKL0

    Apparently, Security Development Lifecycle (SDL) recommended checks which include enabling additional secure code generation features and extra security-relevant warnings as errors.

    The steps to solve this issue are:

    1. Go to Project-> "your project name" Properties
    2. Under Configuration Properties, go to C/C++
    3. Under C/C++, go to Preprocessor 
    4. Select Preprocessor Definitions and click on Edit from the dropdown menu
    5. In the blank space fill out _CRT_SECURE_NO_WARNINGS
    
    0 讨论(0)
  • 2020-12-01 04:43

    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.

    0 讨论(0)
  • 2020-12-01 04:45

    enter at the beginning of the program:

    #pragma warning(disable : 4996)
    

    and that's it.

    0 讨论(0)
  • 2020-12-01 04:50

    You can also disable specific warning numbers in C/C++ > Advanced > Disable Specific Warnings.

    0 讨论(0)
  • 2020-12-01 04:56

    Just to add to this, _CRT_NONSTDC_NO_DEPRECATE worked for me in VS2019. _CRT_SECURE_NO_WARNINGS alone did not clear this for me (I have both defined).

    Similar to the other answers, this may be added by right-clicking the project in Solution Explorer, Then going to Properties->Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions->Edit... then adding the line _CRT_NONSTDC_NO_DEPRECATE.

    0 讨论(0)
  • 2020-12-01 05:02

    Project ->project_name properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions -> Edit... add line _CRT_SECURE_NO_WARNINGS

    0 讨论(0)
提交回复
热议问题