我在覆盖文件流的<<和>>运算符时遇到了问题。
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;
}当我尝试以同样的方式覆盖iostream时,我没有遇到问题,只是文件流而已。你能指出我哪里做错了吗?
发布于 2015-10-15 11:50:17
您似乎混淆了输入的ifstream (in-filestream的缩写)和输出的ofstream (out-filestream的缩写)。
https://stackoverflow.com/questions/33139333
复制相似问题