为什么g ++会显示"gets()"?即使在包含< cstdio>之后也未声明 [英] why g++ shows "gets()" not declared ,even after including <cstdio>

查看:112
本文介绍了为什么g ++会显示"gets()"?即使在包含< cstdio>之后也未声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int main()
{
    char str[30];
    gets(str);
}

当我使用gets()函数编译器时,出现以下错误

when i use gets () function compiler gives me the following error

error: 'gets' was not declared in this scope

我当时将G ++与geany ide一起使用

i was using G++ with geany ide

请简化解决方案,因为它是初学者.

please make the solution simple cuz iam a beginner.

推荐答案

gets在C ++ 11中已弃用,并从C ++ 14中删除.如果您使用的是GCC6.0或更高版本,则默认情况下它将使用C ++ 14,并且将不可用.而不是使用

gets was deprecated in C++11 and removed from C++14. If you are using GCC6.0 or newer then by default it uses C++14 and won't be available. Instead of using

main()
{
    char str[30];
    gets(str);
}

使用

int main()
{
    std::string str;
    std::getline(cin, str);
}

这篇关于为什么g ++会显示"gets()"?即使在包含&lt; cstdio&gt;之后也未声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆