How do I?: Add more statements.

Borland Turbo C++ 4.5
Hi guys, while I was searching for information about the keyword "operator" to better understand it, I found this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream.h>
class Complex
{
public:
	Complex(float re, float im) : myReal(re), myImag(im){}
	friend istream& operator>>(istream&, Complex&);
	friend ostream& operator<<(ostream&, const Complex&);
private:
	float myReal;
	float myImag;
};

istream& operator>>(istream& in, Complex& c)
{
	double real, imag;
	in >> real >> imag;
	if (in.good())
	{
		c.myReal = real;
		c.myImag = imag;
	}
	return in;
}

ostream& operator<<(ostream& out, const Complex& c)
{
	out << "(" << c.myReal << "," << c.myImag << ")";
	return out;
}

void main()
{
	// Add more statements here.
}


I wondered what the output for this code. I've been trying to call the functions available in the class of "Complex" by function "main", but to no avail. So, can you add the code in the function "main"? where it will call the functions in the class of "Complex" so that I can see the output for this code and how it works. Thank you.
1
2
3
4
Complex c;
cout << "Enter two numbers :";
cin >> c;
cout << "Here's your c :" << c;
Thanks hamsterman..! :)
Last edited on
Topic archived. No new replies allowed.