In C, I'm using printf("%+10.5d\n", x); to print the integer x.
I've written a small test case for C++ io manipulators, but the output has a different format:
#include <iostream>
#include <iomanip>
#include <cstdio>
int main(void)
{
int x = 3;
printf("%+10.5d\n", x);
std::cout << std::showpos << std::setw(10) << std::setprecision(5) << x << std::endl;
return 0;
}
The output is:
./testcommand +00003 +3
Which io manipulator I am missing here to get the same output as with printf?
std::setfill
http://www.cplusplus.com/reference/iostream/manipulators/setfill/
with a short if statement
((x>0) ? "+" : "" )
so:
std::cout << ((x>0) ? "+" : "" ) << std::setfill('0') << std::setw(10) << std::setprecision(5) << x << std::endl;