how do I make fstream's >> work for my class?
hi, it's me again :)
I've got a crazy idea, which I am trying to get working. I've coded a class called Float. it looks something like this:
Code:
class Float
{
public:
Float();
~Float();
// here come some operators
//...
//at last the value of the float
float Value;
}
everything is working fine besides one small detail. When I tried to do something like:
Code:
Float SomeFloat;
ifstream SomeFile("my_file");
SomeFile>>SomeFloat;
I got a lot of errors. That was really not surprising, since fstream (or, in this case ifstream) hasn't got an operator>> for my class Float.
My question is, can I make fstream (and ifstream) somehow recognize my Float class so that I can simply do SomeFile>>SomeFloat?
At the same time I want to avoid things like:
Code:
SomeFile>>SomeFloat.Value;
(it looks rather nasty and besides that I want to keep Value protected)
thnx :)