为什么scanf 函数报错 在C++文件当中。平台VS2013
怪我咯
怪我咯 2017-04-17 12:00:20
0
5
633

include<stdio.h>

include<stdlib.h>

void main()
{
int tmp;
printf("请输入需要查找的数值\n");
scanf("%d",&tmp);
system("pause");
}

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(5)
大家讲道理

c:code二分查找二分查找source.cpp(11): error 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.
1> c:program files (x86)microsoft visual studio 12.0vcincludestdio.h(283) : see declaration of 'scanf'

巴扎黑

If you can speak English, you should be able to understand the compiler prompts. Starting from a certain version of VS, most of the input and output functions in the original stdio, such as printf, are marked as unsafe. It used to be a warning. It is possible It's because you turned on -Wall, or it may be that the error is forced directly now. Just switch to a safe version like printf_s. The usage is basically similar. For details, you can check msdn

左手右手慢动作

What is written upstairs is not the point. The point is that C++11’s strict overflow check solution for strings: you just need to replace scanf with scanf_s

阿神

Header file<cstdio.h>

伊谢尔伦

VS2013 has mandatory security checks. scanf is an unsafe function. It is recommended to use scanf_s in the c+11 standard. If you don’t want to use it, you can #define _CRT_SECURE_NO_WARNINGS at the beginning of the header to skip the security check!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template