Niv*_*R.S 0 c++ string gcc g++ geany
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
char str[30];
gets(str);
}
Run Code Online (Sandbox Code Playgroud)
当我使用gets()函数编译器给我以下错误
error: 'gets' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
我在 geany ide 中使用 G++
请使解决方案简单,因为我是初学者。
gets在 C++11 中被弃用并从 C++14 中删除。如果您使用 GCC6.0 或更新版本,那么默认情况下它使用 C++14 并且将不可用。而不是使用
main()
{
char str[30];
gets(str);
}
Run Code Online (Sandbox Code Playgroud)
用
int main()
{
std::string str;
std::getline(cin, str);
}
Run Code Online (Sandbox Code Playgroud)