//simple << operator overloading example in C++
#include<iostream.h>
#include<conio.h>
using namespace std;
class log
{
int s;
public:
friend ostream &operator<<(ostream &, log &);
};
ostream &operator<<(ostream &dout,log &a)
{
dout<<"Enter a value of s : ";
cin>>a.s;
dout<<"Hey"<< a.s;
return (dout);
}
int main()
{
log a1;
cout<<a1;
getch();
}
/* OUTPUT:
Enter a value of s : 6 [6 is input data from user]
Hey6*/
No comments:
Post a Comment