For a hw assignment for a Time class I have the instructions to overload the extraction operator, however the input format has to be the same as the output which is (days~HH:MM:SS). This is what i have for the operator: header file
friend ostream& operator<<(ostream& out, const Time& t);
friend istream& operator>>(istream& in, Time& t);
cpp file
istream& operator>>(istream& in, Time& t)
{
in >> t.day;
in >> t.hour;
in >> t.minute;
in >> t.second;
if (t.day < 0 || t.hour < 0 || t.minute < 0 || t.second < 0)
{
t.day = t.hour = t.minute = t.second = 0;
}
//else
return in;
}
main file for output
cout << "Enter first Time object (DAYS~HH:MM:SS): "; cin >> t1;
cout << t1;
when i go to output a Time object, however, it only prints out days and 00:00:00 afterwards, as if I didn't get the rest of them. How can I get days into t.day, HH into t.hour, etc... The examples in my book show distance examples but none where I have to extract from a stream, they normally ask for the input of each separate part. How can I do this all at once from the format I listed?