So, I'm a beginner at c++. I have an assignment where I have to use a struct for time length and use operator overloading to input a time length (minutes and seconds) separated with ':'. So my question: How can I let the compiler know that ':' is an enter (so it registers the minutes)? So if I fill in for example 2:40, It should be registered like this: length.minutes = 2 and length.seconds = 40
struct Length
{
int minutes; // #minutes (0..)
int seconds; // #seconds (0..59)
};
Length l1 = {42,42}, l2 = {0,0}, l3 = {3,21}, l4 = {3,14};
istream& operator>> (istream& in, Length& length)
{// Precondition:
assert (true) ;
/* Postcondition:
the value of length has been read from in: first minutes, then ':', then seconds
*/
in >> length.minutes >> ':' >> length.seconds;
}