overloaded istream operator issue

I am on the final portion of my project and need to incorporate an overloaded istream operator, I have defined it correctly to my knowledge, but I can't get it work properly...

any help is greatly appreciated
1
2
3
4
5
istream &operator>>(istream &in, Saving &S1)
{
	getline(in, S1.name);
	return in;
}


And this is how I use it
 
cin >> name;


name is part of a base class where Saving is a derived class using inheritance and name is a string.
The overloaded istream operator is :
istream &operator>>(istream &in, Saving &S1)

So to use it you should be doing:
1
2
3
Saving S;

cin >> S;


You may have issues with getline(in, S1.name) if name is a private/protected member.
If name is public, then the overloaded istream operator is basically redundant anyway, because
you can just do:
1
2
3
Saving S;

cin >> S.name;

or if the name will contain spaces
1
2
3
Saving S;

getline (cin,S.name);
Last edited on
Topic archived. No new replies allowed.