Advertisements
So I made a sloppy clock program as an assignment. It works fine however I want the output to display each cout as "01:02", instead it displays "1:2", even though I think I have written all the right manipulators. This is my whole program.
#include <thread>
#include <chrono>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <stdlib.h>
using namespace std;
int main()
{
cout << fixed << right;
cout.fill(0);
for (int m = 0; m < 59; m++)
{
for (int s = 0; s < 59; s++)
{
this_thread::sleep_for(
chrono::seconds(1));
system("cls");
cout << setw(2) << m << ":";
cout << setw(2) << s << endl;
}
}
}
>Solution :
You are using the null character to fill (which is not visible).
cout.fill(0);
What you probably meant was to use the ASCII character 0
, like this:
cout.fill('0');