VS2017, when I use FILE to write, I encounter the following error
'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
After a search attempt, adding _CRT_SECURE_NO_WARNIN and so on in the steps [Open Project >> Properties >> C/C++ >> Preprocessor >> Preprocessor Definition] has no effect.
It was finally solved like this:
Add at the front of the program: #define _CRT_SECURE_NO_DEPRECATE to solve the problem.
#define _CRT_SECURE_NO_DEPRECATE
Give a chestnut:
#define _CRT_SECURE_NO_DEPRECATE //加到此处解决问题
#include <iostream>
using namespace std;
void main()
{
FILE *fp = fopen("myFileFp.txt","w");
char str[] = "hello world !";
for (int i = 0; i < 1000; i++)
{
fprintf(fp," 第 %d 个 %s ;\n",i,str);
}
fclose(fp);
}
After the file is opened: from 0-999 hello world!;
Put the information you found here for reference:
The most complete solution to solve the fopen and fscanf requirements in VS to be replaced with fopen_s and fscanf_s -------------- ps: If you encounter the above problems when using MFC, you can use the third method to solve the first method : Add #define _CRT_SECURE_NO_DEPRECATE at the top of the program;
Method 2: Add #define _CRT_SECURE_NO_WARNINGS at the top of the program;
Method 3: Add #pragma warning(disable:4996) at the top of the program;
Method 4: Change scanf, scanf to scanf_s, fopen_s, please Baidu for specific method;
Method 5: There is no need to add that line of code at the top of the program, just uncheck "SDL check" when creating a new project;
Method 6: If the project has been established, you can also close SDL in the project properties;
Method 7: Just set it in the project; put the macro definition that reported the error in the project properties-C/C+±- preprocessor-preprocessor definition;
Method 8: In the project properties-c/c++-command line, add: /D _CRT_SECURE_NO_WARNINGS.
End:
Sharing is also a way to deepen your understanding of the problem again. It may not be comprehensive, but it is definitely useful and will continue to be improved later~