新版Visual Studio编译旧版本程序提示使用scanf_s

1.问题描述

更新Visual Studio后,编译旧版本程序失败,提示使用“scanf_s”函数。

新版Visual Studio编译旧版本程序提示使用scanf_s

2.解决办法

1)直接将“scanf”函数修改为“scanf_s”函数,并增加缓存大小限定参数,可正确编译运行。

2)在源文件开始处增加“#pragma warning(disable:4996)”预处理命令,强制调用原版本函数。

3)关闭VS安全检查。具体步骤如下:

a)项目->属性

新版Visual Studio编译旧版本程序提示使用scanf_s

b)配置属性->C/C++->代码生成

新版Visual Studio编译旧版本程序提示使用scanf_s

c)安全检查->选择“否”

新版Visual Studio编译旧版本程序提示使用scanf_s

以上三种方式,根据自己需求选择。