urgently need code to be corrected

kpsg25690's Avatar, Join Date: Aug 2009
Go4Expert Member
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(); 
}
naimish's Avatar
Banned
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.
naimish's Avatar
Banned
Line 18: error: conio.h: No such file or directory
Line 16: error: 'x' has not been declared
compilation terminated due to -Wfatal-errors.
kpsg25690's Avatar, Join Date: Aug 2009
Go4Expert Member
Quote:
Originally Posted by naimish View Post
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.
I use turbo c++ not ansi c++ so i have to use <iostream.h> and not otherwise.
naimish's Avatar
Banned
Check my 2nd answer please.
kpsg25690's Avatar, Join Date: Aug 2009
Go4Expert Member
Quote:
Originally Posted by naimish View Post
Check my 2nd answer please.
the second answer is partially correct as x is not declared but i have to use <conio.h>
for above mentioned reasons.....
naimish's Avatar
Banned
So it means, accept X, the rest is fine
kpsg25690's Avatar, Join Date: Aug 2009
Go4Expert Member
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"
naimish's Avatar
Banned
Could you please re-pate the code over here ?
kpsg25690's Avatar, Join Date: Aug 2009
Go4Expert Member
here you go..
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(); 
}