I have a simple question. I'm using a class that inputs time (my_time, your_time) in terms of hrs:mins. I've got the whole program figured out except for one little thing -- where the digits are less than ten I need to add a leading zero to it (so 5:1 becomes 05:01).
I would just do a setw and fill the empty spaces with zeros, but I'm not having the hrs and mins entered seperately.
Here is my input (the >> is overloaded):
in main:
cin >> your_time;
in class:
1 2 3 4 5 6 7 8 9
void time24::input(istream& fin)
{
char ch;
if (&cin == &fin)
cout << "Enter time in the form 01:23 > ";
fin >> hrs >> ch >> mins;
normalize();
}
I don't see how leading zeroes on input is a problem. It should work either way as is. Output is your
only problem, and a combination of std::setw( 2 ) and std::setfill( '0' ) should do the trick.