gets() function is not available in Visual studio 2015 community

后端 未结 4 1908
-上瘾入骨i
-上瘾入骨i 2021-02-08 13:29

I have faced a compiler error(c3861) in my newly installed Visual studio community 2015 IDE:

I just want to use gets() function from stdio.h library, a

相关标签:
4条回答
  • 2021-02-08 13:50

    if you are looking forward to learn about

    buffer overflow vulnerability

    you simply can use it and anther unsafe functions by the fallowing steps

    1. from the solution explorer right click on the project and choose properties
    2. navigate to Configuration Properties >> C/C++ >> Advanced
    3. change Compile As value to Compile as C Code (/TC)
    4. (optional) if you would like to disable the warning just put its warning number in disable specific warning
    0 讨论(0)
  • 2021-02-08 13:54

    gets and_getws are removed from the beginning of vs 2015 because these functions are obsolete. Alternative functions are gets_s and _getws_s.

    0 讨论(0)
  • 2021-02-08 13:55

    The gets function was considered too dangerous (because it can easily cause a buffer overflow), so it was removed from the latest revisions of both C and C++.

    You are supposed to use fgets instead. With that function you can limit input to the size of your buffer.

    0 讨论(0)
  • 2021-02-08 14:06

    Since C11, gets is replaced by gets_s. The gets() function does not perform bounds checking, therefore this function is extremely vulnerable to buffer-overflows. The recommended replacements are gets_s() or fgets()

    gets_s(buf);
    fgets(buf, sizeof(buf), stdin);
    
    0 讨论(0)
提交回复
热议问题