请问这段代码有什么问题??
#include<stdio.h>int main(void)
{
float weight;
float value;
printf("Are you worth your weight in platinum? \n");
printf("Let`s check it out. \n");
printf("Please enter your weight in pounds:");
scanf("%f", &weight);
value = 1700.0*weight * 14.5833;
printf("Your weight in platinum is worth $%.2f.\n", value);
printf("You are easily worth that!If platinum prices drop,\n");
printf("eat more to main tain your value.\n");
return 0;
}
这个是编译器给出的错误解释:
错误 C4996 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
本帖最后由 sunrise085 于 2020-11-5 14:35 编辑
新版的编译器中认为scanf不安全,让使用scanf_s替换。你把scanf换乘scanf_s试试
或者在文件开头加一句:
#define _CRT_SECURE_NO_WARNINGS 我这里运行没有问题。出现这个警告是编译器引起的
解决方法如下:
一:将原来的旧函数替换成新的安全函数,比如scanf_s函数
二:更改预处理定义:
项目->属性->配置属性->C/C++ -> 预处理器 -> 预处理器定义,增加:_CRT_SECURE_NO_DEPRECATE
三:在预编译头文件 stdafx.h 里(要在没有include任何头文件之前)定义下面的宏:
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
(方法来源于网络,没有亲自试验) 还没解决吗? 楼上几位说的方法是可以的,我说一下另外一种,在项目属性里改下SDL检查设置
页:
[1]