How to use _CRT_SECURE_NO_WARNINGS
Add by
Configuration Properties>>C/C++>>Preporocessor>>Preprocessor
Definitions>> _CRT_SECURE_NO_WARNINGS
How to disable a warning in Visual Studio 2015 for C?
In later versions of Visual Studio, additional security checks are enabled by default on new projects, which makes the warning you see be treated as an error.
So, in addition to the actions in the suggested duplicate questions, you may also need to do the following.
Right click on the project in the solution explorer and choose Properties from the menu, then make sure you turn off SDL checks as shown in the following screenshot:
UPDATE (This alone worked for me):
c++ _CRT_SECURE_NO_WARNINGS warning
As the warning says, it's more safe to use _swprintf_s instead. The _s function require the size of the buffers and are therefore more safe against buffer overruns.
fopen deprecated warning
It looks like Microsoft has deprecated lots of calls which use buffers to improve code security. However, the solutions they're providing aren't portable. Anyway, if you aren't interested in using the secure version of their calls (like fopen_s), you need to place a definition of _CRT_SECURE_NO_DEPRECATE before your included header files. For example:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
The preprocessor directive can also be added to your project settings to effect it on all the files under the project. To do this add _CRT_SECURE_NO_DEPRECATE to Project Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions.
Adding _CRT_SECURE_NO_WARNINGS definition using cmake
Use this:
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
See here for the official documentation.
The general form is:
add_definitions(-DFOO -DBAR ...)
Note that, if it's intended for a single target, you should rather use target_compile_definitions
.
Related Topics
Std::Auto_Ptr to Std::Unique_Ptr
C++ Singleton VS. Global Static Object
Overriding Non-Virtual Methods
How to Write C++ Getters and Setters
Std::To_String - More Than Instance of Overloaded Function Matches the Argument List
Scope of Using Declaration Within a Namespace
Will C++ Exceptions Safely Propagate Through C Code
Specialization of Templated Member Function in Templated Class
How Does Virtual Method Invocation Work in C++
Compile a Dll in C/C++, Then Call It from Another Program
How to Get Total CPU Usage in Linux Using C++
Default Argument in the Middle of Parameter List
Reinterpret_Cast VS. C-Style Cast
C++11 Static_Assert and Template Instantiation
Why Does Std::Map Operator[] Create an Object If the Key Doesn't Exist