Hi all,
How to display single digit int as four digit in C++.For example, i want to display the digit 12 as 0012 and 8 as 0008.
Hi all,
How to display single digit int as four digit in C++.For example, i want to display the digit 12 as 0012 and 8 as 0008.
Set the width to 4 and the fill character to '0'. This can be easily done by #include <iomanip> with:
By the way, we don't normally consider 12 to be a digit, unless you are expressing the number in base 13 or more.Code:std::cout << std::setw(4) << std::setfill('0') << num << std::endl;
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)