如果我们写出这样的代码:
1int _tmain(int argc, _TCHAR*
argv[])
2 {
3 fopen("test.txt","r");
4 return 0;
5}
2 {
3
4
5}
在vs 2005,2008下,会收到如下警告:
c:"documents and settings"administrator"桌面"test"test.cpp(9) : warning C4996: '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.
正如这个警告所言,产生的原因时这个方法不是安全的CRT,当然,建议使用安全的CRT,但如果不想用(有时候为了安全性,得多写几行代码),要禁止这个警告,得定义一个宏
#define _CRT_SECURE_NO_WARNINGS
但是注意正确的做法应该是
1#define _CRT_SECURE_NO_WARNINGS
2#include <stdio.h>
2#include <stdio.h>