+1

Gets function should have a prototype error is coming. What should i write.

https://code.sololearn.com/c2RYwcM8F1ib/?ref=app

c++

3/30/2020 5:23:23 AM

Disha Dey

18 Answers

New Answer

+3

gets() has been removed since C++14. You can't use it in modern C++. It is C function. In C++ there is getline() function; Your code is mix of C and C++ If you want to use C++, you can rewite your code as follow: #include <iostream> #include <string> using namespace std; class read { string a,b; public: void display() { cout<<"enter the first string"; cin>>a; cout<<"enter the second string"; cin>>b; a+=b; cout<<"strings obtained on concatenation "<<a<<"\n"; } }; int main() { read r; r.display(); getchar(); }

0

I have also searched for this but I didn't get it , even professional haven't given answer for this . I don't know why but I will suggest you to don't use this declaration (gets())as this is very sensitive and hard to be mastered also no one cares this function with this c language .Thanks for asking your doubt🤗

0

Then what should i write instead of gets()

0

Mr. Dacco Samanta, by using Char* I'm still getting the error and apart from that 2 more errors are coming.

0

Mr.Andriy Kan, this program is showing 6 error and 1 warning.

0

Disha Dey What kind of errors? May be you are using wrong (or old) compiler? In your code was #include<conio.h> It was used on DOS compilers. gets was defined in stdio c-header file you can try to include this header file if you are using old DOS compiler. try this (you should enter 2 strings when you run program): https://code.sololearn.com/c4iJF6vQU9L8

0

Yes it's the old one. But i have tried the way you showed but still I'm getting error.

0

which compiler do you use? turbo (borland) C?

0

0

then add line at the top of your code: #include <stdio.h> function gets is defined inside it

0

Use getline(cin, stringname);

0

Mr. yash Tärkár, now getline should have a prototype error is showing.

0

Have you typed using namespace std; below the header files?

0

3 error are showing after writing namespace std;

0

Did you try to append #include <stdio.h> at the top of the file? also semicolon in line #15 should be at the end of the line (not inside string). I appended #include <stdio.h> in your file and fixed line#15 This code will not compile in CodePlayground!!!!! Try to compile it with your turbo C++ https://code.sololearn.com/cc4o4o3N4Fgl

0

But I'm doing c++ not c so why would be there <stdio.h >.

0

Disha Dey because you use C function gets() It is defined inside stdio.h file header.

0

If you don't want to use stdio.h then you should not use gets function use C++ streams: cin>>a; instead of gets(a); and cin>>b; instead of gets(b);