What I'm trying to is to write something like this
file << someFunction(5) << hex << 3;
And to get an output like this 00003
instead of 3 (and 300 will be 00300, etc)
Note:- Sorry if this was asked before, I don't know what term to search for to get this
EDIT:- I mean the zero's to the left, i included the hex part just to be clear I want it to be compatible with this format
1 decimal place (tenths) 2 decimal places (hundredths) 3 decimal places (thousandths) 4 decimal places (ten-thousandths)
the 5 is in the thousandths place.
The whole number is on the left side of the decimal point and the fractional part is on the right side of the decimal point. The decimal point makes it simple to read a decimal number.
The first digit after the decimal represents the tenths place. The next digit after the decimal represents the hundredths place. The remaining digits continue to fill in the place values until there are no digits left.
I believe this is what you mean.
#include <iostream>
#include <iomanip>
int main()
{
std::cout << std::setw(5) << std::setfill('0') << 3 << '\n';
return 0;
}
Output
00003
Links
setw
, setfill
.
Edit: Also, see std::internal
at this question.
Use
file << setfill('0') << setw(5) << 3;
to get 00003
instead of 3
iomanip is what you need to search for.
#include <iomanip>
then
file << someFunction(5) << hex << setw(5) << setfill('0') << 3 << endl;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With