【发布时间】:2016-02-07 05:47:25
【问题描述】:
使用以下代码,我得到“gets() 未在此范围内声明”错误:
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
// string str[]={"I am a boy"};
string str[20];`
gets(str);
cout<<*str;
return 0;
}
【问题讨论】:
-
阅读gets manual。它告诉您需要包含哪个头文件。但请注意它在结尾处所说的内容:“永远不要使用gets()。因为事先不知道数据是不可能知道gets() 将读取多少个字符,并且因为gets() 将继续存储字符超过缓冲区的末尾,使用它非常危险。它已被用来破坏计算机安全性。请改用 fgets()。"
标签: c++