Help in a class for Complex Numbers

I was making a class for Complex Numbers.
I want to know one thing though.

Say I create a class Complex_t.
It has a string Num. It will store the Complex Number as A + Bi where A and B are two values I put in it through a string stream.

I have an object Complex, of type Complex_t.

My question is this:
 
cout << Complex;


Is there a way to make it such that it will print Num from Complex?
I have tried overloading << operator, but it didn't work!

Any help?
Try making a friend class out of ostream:

1
2
3

friend ostream &operator << ( stream &Out, const Complex_t &C );
Last edited on
@kooth:
isn't ostream a predefined class?
How am I to edit that? (of course without fiddling with the header files!)
1
2
3
4
5
6
7
8
9
10
11
12
13
14

/*    NOTE: Not part of your class, that's why you need the friend statement:    */

ostream @operator << ( ostream &Out, const Complex_t &C )
    {
    Out << C.Num.data();

    return Out;

    }
        /*    operator <<    */


Topic archived. No new replies allowed.