I already looked at this thread , but it does not account for the use of negative numbers if I use setfill ('0').
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int num1;
cin >> num1;
cout << setw(5) << setfill( '0' ) << num1 << endl;
return 0;
}
Using this method, if I enter “5”, it will display as “00005”. But if I enter -5, it will display as "000-5"
How can I fix this so that out-put is "-0005"?
source
share