title: How to understand the instructions of an istream function?
body: <p>I am writing a function to the stream and am on the read function to the istream. My ostream function looks like this:</p>
  <pre><code> ostream&amp; Time:: write(ostream&amp; ostr)const {
  
  
        int hour;
        int minutes;
  
        hour = m_min / 60;
        minutes = m_min % 60;
  
       // Time::write(ostr);
        ostr &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; hour;
        ostr &lt;&lt; setfill('0') &lt;&lt; setw(1) &lt;&lt; &quot;:&quot;;
        ostr &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; minutes;
  
        return ostr;
     }
  </code></pre>
  <blockquote>
  <pre><code> std::istream&amp; read(std::istream&amp; istr);
  </code></pre>
  <p>Reads the time form a stream in H:M format. It makes sure that the two integers (hours and minute) are separated by &quot;:&quot;, otherwise it will set the istream object in a failure state. (see the steps below to see how)</p>
  <p>Note that this function does not react to any invalid data. It simply follows these steps:</p>
  <ul>
  <li><p>reads the integer for the hours using istr</p>
  </li>
  <li><p>reads one character and makes sure it is ':', if it is not is will set the istream object a failure state by issuing this command:</p>
  <pre><code>istr.setstate(ios::failbit);
  </code></pre>
  </li>
  <li><p>reads the integer for the minutes using istr</p>
  </li>
  </ul>
  <p>Note: Do not clear or flush the istream since this method complies with the istream standards. The caller of this function may check the istream state to make sure that the read was successful if needed.</p>
  </blockquote>
  <p>So far this is what I have but I am not sure if I am getting what it is asking me to do or if I am doing it right:</p>
  <pre><code>   istream&amp; Time::read(istream&amp; istr) {
        int hour;
        int minutes;
  
        hour = m_min / 60;
        minutes = m_min % 60;
  
  
        istr &gt;&gt; hour;
        if (hour != ':') {
           istr.setstate(ios::failbit);
        }
        istr &gt;&gt; minutes;
  
        cout &lt;&lt; hour &lt;&lt; &quot;:&quot; &lt;&lt; minutes &lt;&lt; endl;
  
     }
  </code></pre>
  <p>Am I doing this right? If not, how should I interpret these instructions?</p>