I am having a sample CPP
program which I am trying to compile using g++
. But after running the command
g++ -o test.out test.cpp
I am getting error
test.cpp:7:6: error: 'gets' is not a member of 'std'
std::gets(ch);
^~~~
test.cpp:7:6: note: suggested alternative: 'less'
std::gets(ch);
^~~~
less
When I check the version of g++
using g++ --version
, I am getting the below output
g++ (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Below is my code
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
char ch[100];
std::gets(ch);
puts(ch);
return 0;
}
Can somebody please try to help me how to fix this? As of now, it is not possible to change the versions. I need to make it run in this same version if possible.
Thanks in advance.