Ad
I Want My Clock Program To Display The Output As 00:00 Instead It Displays It As 0:0 Even Though I Have Used Stream Manipulators
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;
}
}
}
Ad
Answer
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');
Ad
source: stackoverflow.com
Related Questions
- → Comparing two large files are taking over four hours
- → Setting JSON node name to variable value
- → Compiling GLUT using Emscripten
- → Evaluate check box from a scanned image in node.js
- → Find an easy web server framework for mobile game
- → my https C++ code doesn't work on some sites (binance)
- → Error while opening pivx wallet on ubuntu
- → Why sending a POST by AJAX is interpreted by the HTTP Server as OPTIONS and sending by CURL is effectively a PUT?
- → Python reading in one line multiple types for a calculator
- → How do I properly pass an argument to a function
- → Accessing Websql database with Qt
- → Using Mysql C API for c++ codes
- → How do I set constants at run-time in a c++ header file, imported through Cython?
Ad