Question
I need help on how to answer this: The other functions in the Time.cpp file do not need to be answered only the Time::read function,
I need help on how to answer this:
The other functions in the Time.cpp file do not need to be answered only the Time::read function, just trying to figure out how to do this
I got this from here:https://github.com/Seneca-244200/OOP-Project#setting-istream-to-a-fail-state
Time::read
std::istream& read(std::istream& istr);
Reads the time from a stream in H:M format. It makes sure that the two integers (hours and minute) are greater than zero and separated by ":", otherwise it will set theistreamobject to afailure state.
This function does not react to any invalid data, instead, it will work exactly how istream works;It will put the istream in a failure state if anything goes wrongby following these steps:
- reads the integer for the hours usingistrand if the value is negative, it setsthe istream object to a failure state.
- reads one character and makes sure it is':'. If it is not':', it will setthe istream object to a failure state.
- reads the integer for the minutes usingistrand if the value is negative, itsets the istream object to a failure state.
setting istream to a fail state
To set the istream to a fail state manually call the following method of istream:
setstate(ios::failbit);
Note: Do not clear or flush theistreamobject since this method complies with theistreamstandards. The caller of this function may check the state of theistreamobject to make sure that the read was successful if needed.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started