What am I doing wrong with istream?

I've pretty much figured everything out except when trying to overload the '>>'. I seem to be able to get it to cin both my variable but when I want to see what I just cin'd to cout it just shows what I initialized at the beginning of main. Could anyone tell me what I'm doing wrong?

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "std_lib_facilities.h"

class customer {

public:
string first_name;
int pin_number;
	
	customer(string fn,int pin)
		: first_name(fn),pin_number(pin) {}
};	

bool operator==(const customer c1, const customer c2)
{
	return c1.first_name==c2.first_name && c1.pin_number==c2.pin_number;
}

ostream& operator<<(ostream& os,const customer c1)
{
	return os<<c1.first_name<<" "<<c1.pin_number<<"\n";
}

istream& operator>>(istream& is, customer c7)
{
	return is>>c7.first_name>>c7.pin_number;
}

int main()
{
	customer c1("Chris",2830);
	customer c2("Scott",4821);
	customer c3("Chris",2830);
	customer c4("Scott",5316);
	customer c7("",0);

	if(c1==c3)
		cout<<"They are the same\n";
	else
		cout<<"Not the same\n";

	if(c1==c2)
		cout<<"They are the same\n";
	else
		cout<<"Not the same\n";

	if(c2==c4)
		cout<<"They are the same\n";
	else
		cout<<"Not the same\n";

	cout<<c1,c2;
	
	cin>>c7;
	cout<<c7;
	

	
	keep_window_open();
}
nevermind figured it out, but for those wondering you have to put an & in front of the type name. I think I know why this fixes it but I don't want to say and be wrong.

so this
1
2
3
4
istream& operator>>(istream& is, customer c7)
{
	return is>>c7.first_name>>c7.pin_number;
}


to this
1
2
3
4
istream& operator>>(istream& is, customer& c7)
{
	return is>>c7.first_name>>c7.pin_number;
}
Correct.

Without the &, the operator is actually modifying a copy of the customer an not the actual customer you wanted to modify.
Topic archived. No new replies allowed.