>> I change the point, not the std::ifstream &input, or is that change somehow as well?
Oh, sorry. Yes, you are changing input as well because the text is being read from the stream and so the stream will be in a different state after you read from it.
>> I have only used ifstream before, so it was easier there and then.
Ok. The reason you use istream is that it is the base class of ifstream and allows you to use your operator with stringstreams or cin. If you are only using ifstreams and don't want to use code you haven't learned then that's fine, just know for the future that istream is the better solution.
>> Why would you return input?
Take code like this:
Code:
std::ifstream in("points.txt");
Point p1, p2;
in >> p1 >> p2;
That last line is just calling the operator>> function twice. It goes from left to right:If you change it to function notation it looks like this:
Code:
operator>>(operator>>(in, p1), p2);
The function in blue is called first. Then the return value of that function is passed to the function in red. You want to pass an input stream as the first parameter to the function in red, which is why the operator>> has to return that input stream. The return value is just ignored if you don't combine operators.
Also, remember that input is modified by the values being read from it for p1, so we have to pass the modified stream to the second call so that p2 gets the next set of values from the stream instead of the same ones as p1.