Breaking News
Loading...

Overloading the output operator in c++


#include <iostream>
using namespace std;

class x
{
    int i;
public:
    x(int k)
    {
        i=k;
    }
    friend ostream& operator<<(ostream& os, const x& d1);
};

ostream& operator<<(ostream& os, const x& d1)
{
    os << d1.i ;
    return os;
}

int main()
{
    x s1(20);
    cout << s1;
}

0 comments:

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
Toggle Footer