i need to get this code debugged .... thank you in advance.. Code: #include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> class str { public: char s[100]; str() {;} str(char *ch) { strcpy(s,ch); } void concat(x,y) { s=strcat(x,y); } void showdata(ch) { puts(ch); } void getdata() { cout<<"\nEnter the string:"; gets(s); } }; void main() { clrscr(); char a[100],b[100],ch[100]; cout<<"\n\t\t\tCreating an uninitialised object"; str c,c2; puts(c.s); cout<<"\n\t\t\tCreating an object with string constants"; str c1("Hello World"); puts(c1.s); cout<<"\nEnter two strings:"; gets(a); gets(b); c2.s=c2.concat(a,b); cout<<"\nEnter a string to be displayed:"; gets(ch); c.showdata(ch); getche(); }
iostream.h, line 1: catastrophic error: #error directive: <iostream.h> is not a Standard header, use <iostream> instead. Note that when you change this header name, that identifiers such as "cout" and "endl" will no longer work, as they are in namespace "std", so use be "std::cout" and "std::endl" respectively. 1 catastrophic error detected in the compilation of "ComeauTest.c". Compilation terminated.
Line 18: error: conio.h: No such file or directory Line 16: error: 'x' has not been declared compilation terminated due to -Wfatal-errors.
the second answer is partially correct as x is not declared but i have to use <conio.h> for above mentioned reasons.....:happy:
replacing x and y by char *x and char *y solved that problem but now the strcat function shows the error line 18:"Lvalue required" line 44:"Not an allowed type"
here you go..:wacky: Code: #include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> class str { public: char s[100]; str() {;} str(char *ch) { strcpy(s,ch); } void concat(char *x,char *y) { s=strcat(x,y); } void showdata(char *ch) { puts(ch); } void getdata() { cout<<"\nEnter the string:"; gets(s); } }; void main() { clrscr(); char a[100],b[100],ch[100]; cout<<"\n\t\t\tCreating an uninitialised object"; str c,c2; puts(c.s); cout<<"\n\t\t\tCreating an object with string constants"; str c1("Hello World"); puts(c1.s); cout<<"\nEnter two strings:"; gets(a); gets(b); c2.s=c2.concat(a,b); cout<<"\nEnter a string to be displayed:"; gets(ch); c.showdata(ch); getche(); }
Line 18: error: conio.h: No such file or directory t.cpp: In member function 'void str::concat(char*, char*)': Line 18: error: incompatible types in assignment of 'char*' to 'char [100]' compilation terminated due to -Wfatal-errors.
that does not solve the problem. okay the error is detected but what am i supposed to do to correct it.