I read this on Accelerated C++. Here is a simplified version.
istream& read_hw(istream& in, Student_info& s)
{
in >> s.name >> s.midterm >> s.final;
return in;
}
Then, we can call the function as:
Student_info s;
read_hw(cin, s);
My question is,
You should read the next paragraph:
Returning the stream allows our caller to write
if (read_hw(cin, homework)){/*...*/}as an abbreviation for
read_hw(cin, homework); if (cin) {/*...*/}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With