Rumah  >  Soal Jawab  >  teks badan

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

include<stdio.h>

include<stdlib.h>

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

怪我咯怪我咯2715 hari yang lalu606

membalas semua(5)saya akan balas

  • 大家讲道理

    大家讲道理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.0\vc\include\stdio.h(283) : see declaration of 'scanf'

    balas
    0
  • 巴扎黑

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

    英语可以的话,你应该能看懂编译器的提示,从vs某个版本开始,原始的stdio中的绝大多数输入输出函数例如printf都被标记上了unsafe,以前是warning,有可能是你开了-Wall,也可能是现在直接强制error了,换成printf_s这样的安全版本就可以了,用法基本类似,详情可以查阅msdn

    balas
    0
  • ringa_lee

    ringa_lee2017-04-17 12:02:20

    楼上写的都不是重点,重点在于C++11对于字符串严格的溢出检查解决:你至于要把scanf换为scanf_s就行

    balas
    0
  • 阿神

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

    头文件<cstdio.h>

    balas
    0
  • 伊谢尔伦

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

    vs2013有强制的安全检查,scanf属于不安全函数,在c+11 标准中推荐使用scanf_s,不想使用的话就可以在头部最开始的地方#define _CRT_SECURE_NO_WARNINGS 跳过安全检查!

    balas
    0
  • Batalbalas