With the following code, I get the "gets() was not declared in this scope" error:
#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;
}
As gets() is a C style function, so if you need to include it in your c++ code then you need to include the header file called stdio.h and moreover you can only pass a c style string to gets() function not c++ string class. So after slight modification in your code it becomes:
#include <iostream>
#include <string.h>
#include "stdio.h"
using namespace std;
int main()
{
// string str[]={"I am a boy"};
char str[20];`
gets(str);
printf("%s",str);
return 0;
}
The function std::gets()
was deprecated in C++11 and removed completely from C++14.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With