我需要重寫< <運算符,以便它可以輸出小時(int)和溫度(雙精度)的值。<<運算符重寫爲cout int和double值
我想我已經包含了所有必要的部分。提前致謝。
struct Reading {
int hour;
double temperature;
Reading(int h, double t): hour(h), temperature(t) { }
bool operator<(const Reading &r) const;
};
========
ostream& operator<<(ostream& ost, const Reading &r)
{
// unsure what to enter here
return ost;
}
========
vector<Reading> get_temps()
{
// stub version
cout << "Please enter name of input file name: ";
string name;
cin >> name;
ifstream ist(name.c_str());
if(!ist) error("can't open input file ", name);
vector<Reading> temps;
int hour;
double temperature;
while (ist >> hour >> temperature){
if (hour <0 || 23 <hour) error("hour out of range");
temps.push_back(Reading(hour,temperature));
}
}
這是功課? – 2010-12-05 23:57:05
你的問題是什麼?你是要求我們爲你寫你的功能嗎? – Gabe 2010-12-06 00:01:33