zoukankan      html  css  js  c++  java
  • 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

    使用VS2015学习比较传统的C语言使用到scanf来输入报错

    编译时提示:

    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.

    意思是:

    “scanf”:此函数或变量可能不安全。考虑使用scanf_s。要禁用弃用,请使用_CRT_SECURE_NO_WARNINGS。详情请参阅在线帮助。

    原因是:

    其原因是微软认为scanf的使用存在安全隐患,因为C/C++中的字符串处理都是以为截止符的,如果搜索不到,容易出现字符串越界,而scanf输入字符串时也是以空字符结尾。

    解决方法:

    1.在代码开头写入以下定义:

    #define _CRT_SECURE_NO_WARNINGS

    2.使用scanf_s代替scanf:

    scanf_s("%x",& y, z);

    x——占位符

    y——被输入的地址

    z——读取的长度

    gets()函数也一样,可以使用gets_s(x,y)代替

    x——数组名称

    y——读取长度

  • 相关阅读:
    【Longest Common Prefix】cpp
    【WildCard Matching】cpp
    【 Regular Expression Matching 】cpp
    【Longest Palindromic Substring】cpp
    【Add binary】cpp
    【String to Integer (atoi) 】cpp
    【Implement strStr() 】cpp
    【Valid Palindrome】cpp
    【LRU Cache】cpp
    【Reorder List】cpp
  • 原文地址:https://www.cnblogs.com/eve612/p/13809008.html
Copyright © 2011-2022 走看看