c++ - overriding istream and ofstream -
im having trouble overriding <<
, >>
operators file stream.
struct reading { int hour; double temp; reading() : hour{ 0 }, temp{ 0 } {}; reading(int h, double t) : hour{ h }, temp{ t } {}; }; ifstream& operator<<(ifstream& ifs, const reading& reading) { return ifs << '(' << reading.hour << ',' << reading.temp << ')' << endl; } ofstream& operator>>(ofstream& ofs, reading& reading) { ofs >> reading.hour; ofs >> reading.temp; return ofs; }
i don't have problem when try override iostream in same manner, file stream. indicated i'm doing wrong please?
you seem have confused ifstream
(short in-filestream) input , ofstream
(short out-filestream) output.
Comments
Post a Comment