fopen在vs2012中没法编译通过
fopen在vs2012中无法编译通过
该代码可以在vc6.0和vs2008、vs2010下编译运行,却不能在vs2012下编译通过
错误:
1>e:\project\consoleapplication2\consoleapplication2\源.cpp(14): error 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.
1> d:\program files (x86)\microsoft visual studio 11.0\vc\include\stdio.h(218) : 参见“fopen”的声明
还请各位指教,应该怎么修改!
------解决方案--------------------
Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
提示讲的很清楚的。
要么换函数,要么加宏。
------解决方案--------------------
这个宏就是为了关闭那个警告/错误的
该代码可以在vc6.0和vs2008、vs2010下编译运行,却不能在vs2012下编译通过
#include <iostream>
#include <cstdio>
#include <memory>
using namespace std;
int main(int argc,char* argv[])
{
if (argc!=3)
{
cout<<"程序使用方法:C3 /r 源文件"<<endl;
return 0;
}
FILE* pFile;
pFile=fopen(argv[2],"r");
if (NULL==pFile)
{
cout<<"打开指定文件失败,请确定指定文件是否存在!\n";
return 0;
}
if (strcmp(argv[1],"/r")==0)
{
char str[100];
memset(str,0,100);
fread(str,1,100,pFile);
cout<<"读取的数据是:"<<str<<endl;
return 1;
}
}
错误:
1>e:\project\consoleapplication2\consoleapplication2\源.cpp(14): error 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.
1> d:\program files (x86)\microsoft visual studio 11.0\vc\include\stdio.h(218) : 参见“fopen”的声明
还请各位指教,应该怎么修改!
------解决方案--------------------
Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
提示讲的很清楚的。
要么换函数,要么加宏。
------解决方案--------------------
这个宏就是为了关闭那个警告/错误的