c++: Input minutes and seconds separated with ':'
up vote
2
down vote
favorite
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;
}
c++ operator-overloading c++17
add a comment |
up vote
2
down vote
favorite
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;
}
c++ operator-overloading c++17
stackoverflow.com/a/9832875/845092
– Mooing Duck
Nov 7 at 17:54
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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;
}
c++ operator-overloading c++17
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;
}
c++ operator-overloading c++17
c++ operator-overloading c++17
edited Nov 7 at 17:56
asked Nov 7 at 17:52
ilivss
234
234
stackoverflow.com/a/9832875/845092
– Mooing Duck
Nov 7 at 17:54
add a comment |
stackoverflow.com/a/9832875/845092
– Mooing Duck
Nov 7 at 17:54
stackoverflow.com/a/9832875/845092
– Mooing Duck
Nov 7 at 17:54
stackoverflow.com/a/9832875/845092
– Mooing Duck
Nov 7 at 17:54
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195040%2fc-input-minutes-and-seconds-separated-with%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
stackoverflow.com/a/9832875/845092
– Mooing Duck
Nov 7 at 17:54