+ 1

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

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

30th Mar 2020, 5:23 AM
Disha Dey
Disha Dey - avatar
18 ответов
+ 4
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(); }
30th Mar 2020, 6:07 AM
andriy kan
andriy kan - avatar
+ 1
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
30th Mar 2020, 8:45 AM
andriy kan
andriy kan - avatar
+ 1
which compiler do you use? turbo (borland) C?
30th Mar 2020, 8:52 AM
andriy kan
andriy kan - avatar
+ 1
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
1st Apr 2020, 10:08 AM
andriy kan
andriy kan - avatar
+ 1
Disha Dey because you use C function gets() It is defined inside stdio.h file header.
1st Apr 2020, 10:23 AM
andriy kan
andriy kan - avatar
+ 1
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);
1st Apr 2020, 10:32 AM
andriy kan
andriy kan - avatar
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🤗
30th Mar 2020, 6:00 AM
Dibyendu Samanta
Dibyendu Samanta - avatar
0
Then what should i write instead of gets()
30th Mar 2020, 6:05 AM
Disha Dey
Disha Dey - avatar
0
Mr. Dacco Samanta, by using Char* I'm still getting the error and apart from that 2 more errors are coming.
30th Mar 2020, 8:29 AM
Disha Dey
Disha Dey - avatar
0
Mr.Andriy Kan, this program is showing 6 error and 1 warning.
30th Mar 2020, 8:40 AM
Disha Dey
Disha Dey - avatar
0
Yes it's the old one. But i have tried the way you showed but still I'm getting error.
30th Mar 2020, 8:49 AM
Disha Dey
Disha Dey - avatar
0
Yes
30th Mar 2020, 8:55 AM
Disha Dey
Disha Dey - avatar
0
then add line at the top of your code: #include <stdio.h> function gets is defined inside it
30th Mar 2020, 9:01 AM
andriy kan
andriy kan - avatar
0
Use getline(cin, stringname);
31st Mar 2020, 12:06 PM
Yash Billa
Yash Billa - avatar
0
Mr. yash Tärkár, now getline should have a prototype error is showing.
1st Apr 2020, 9:38 AM
Disha Dey
Disha Dey - avatar
0
Have you typed using namespace std; below the header files?
1st Apr 2020, 9:41 AM
Yash Billa
Yash Billa - avatar
0
3 error are showing after writing namespace std;
1st Apr 2020, 9:47 AM
Disha Dey
Disha Dey - avatar
0
But I'm doing c++ not c so why would be there <stdio.h >.
1st Apr 2020, 10:19 AM
Disha Dey
Disha Dey - avatar