Hi,
Please check my example
I tried with below code for istream and ostream.
If I tries to remove &, I was getting error.
Code:
//One case where friend function becomes necassary
#include<iostream.h>
class emp
{
int age;
float salary;
char name[20];
public:
friend ostream& operator<<(ostream& o, emp& e);
friend istream& operator>>(istream& i, emp& e);
};
ostream& operator<<(ostream&o, emp& e)
{
o<<endl<<e.name<<endl<<e.age<<endl<<e.salary<<endl;
return o;
}
istream& operator>>(istream& i, emp& e)
{
i>>e.name>>e.age>>e.salary;
return i;
}
void main()
{
emp e;
cout<<"Enter name agfe salary of the employee"<<endl;
cin>>e;
cout<<e;
}