【发布时间】:2015-09-02 15:15:57
【问题描述】:
在我的代码中使用gets() 时,编译器会喊叫
warning: the 'gets' function is dangerous and should not be used.`
和
warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638)
[-Wdeprecated-declarations]
有什么具体原因吗?
【问题讨论】:
-
使用
fgets和stdin代替。正如消息所说,gets很危险,因为它没有提供防止缓冲区溢出的保护.. -
“为什么编译器会在这里发出警告?”的字面意思。是“因为编译器的程序员让它这样做了。”