Hi Friends,
I am new to this forum,
I am getting the problem in the following program
The Program is compiling without any errors but while the logic is not working correctly
here my code is
#include<iostream.h>
#include<conio.h>
void main()
{
class operover
{
char x[10];
public:
string()
{}
string(char xx[])
{
strcpy(x,xx);
}
int operator>(string k)
{
if(strcmp(x,k.x)>0)
return 1;
else
return 0;
}
int operator<(string k)
{
if(strcmp(x,k.x)<0)
return 1;
else
return 0;
}
int operator==(string k)
{
if(strcmp(x,k.x)=0)
return 1;
else
return 0;
}
};
void main()
{
string s1("vijay");s2("varma");
if(s1>s2)
cout<<"s1 is big";
else
if(s1<s2)
cout<<"s2 is big";
else
cout<"both are eual";
}
In above program if I have given two strings are same but its not showing both are equal (e.g s1("vijay) and s2("vijay"))
Please any one see my code and let me know where did I mistaked
You have if(strcmp(x,k.x)=0) but it should be if(strcmp(x,k.x)==0), string s1("vijay");s2("varma"); should be string s1("vijay"), s2("varma");, cout<"both are eual"; should be cout<<"both are equal";, <iostream.h> should better be <iostream> (with the std namespace), main should better be int and return 0 at the end
Thank you Bazzy,I did small small mistakes
Now I got the out put correctly
But I have one dought
why we have to declare main as int instead of void main() even though the function is not return any thing
once again thank you for the reply