Is there a way to set by default for all projects removing the precompiler secure warnings that come up when using functions like scanf(). I found that you can do it by adding a line in the project option or a #define _CRT_SECURE_NO_WARNINGS
in the beginning of the code.
I find myself repeatedly creating new projects for solving programming contests and it is really annoying (and takes valuable time) to add:
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
In the beginning of the code, or to set it in the precompiler options every time I start a new project.
Not automatically, no. You can create a project template as BlueWandered suggested or create a custom property sheet that you can use for your current and all future projects.
_CRT_SECURE_NO_WARNINGS
.Now any time you create a new project, add this property sheet like so...
The benefit here is that not only do you get a single place to manage common settings but anytime you change the settings they get propagated to ALL projects that use it. This is handy if you have a lot of settings like
_CRT_SECURE_NO_WARNINGS
or libraries like Boost that you want to use in your projects.my two cents for VS 2017:
I can confirm it works in stdafx.h both in these styles:
a)
b)
(I have added another define for MSDN network calls..) Of course I do prefer a).
I can confirm that: #define _CRT_SECURE_NO_WARNINGS (without a value) DOES NOT WORK.
PS the real point is to put these defines BEFORE declarations of functions, i.e. before *.h
Mark all the desired projects in solution explorer.
Press Alt-F7 or right click in solution explorer and select "Properties"
Configurations:All Configurations
Click on the Preprocessor Definitions line to invoke its editor
Choose Edit...
Copy "_CRT_SECURE_NO_WARNINGS" into the Preprocessor Definitions white box on the top.
It may have been because I am still new to VS and definitely new to C, but the only thing that allowed me to build was adding
At the top of my file, this suppressed the C4996 error I was getting with sprintf
A bit annoying but perfect for my tiny bit of code and by far the easiest.
I read about it here: https://msdn.microsoft.com/en-us/library/2c8f766e.aspx
All the solutions here failed to work on my VS2013, however I put the
#define _CRT_SECURE_NO_WARNINGS
in the stdafx.h just before the#pragma once
and all warnings were suppressed. Note: I only code for prototyping purposes to support my research so please make sure you understand the implications of this method when writing your code.Hope this helps
If your project does not use stdafx.h, you can put the following lines as the first lines in your .cpp file and the compiler warning should go away -- at least it did for me in Visual Studio C++ 2008.
It's ok to have comment and blank lines before them.