Home  >  Q&A  >  body text

为什么scanf 函数报错 在C++文件当中。平台VS2013

include<stdio.h>

include<stdlib.h>

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

怪我咯怪我咯2715 days ago607

reply all(5)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 12:02:20

    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'

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 12:02:20

    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

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 12:02:20

    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

    reply
    0
  • 阿神

    阿神2017-04-17 12:02:20

    Header file<cstdio.h>

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 12:02:20

    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!

    reply
    0
  • Cancelreply