#include <iostream>
#include <locale>
#include <string>
#include <cmath>
// a num_put facet to add a padding space for positive numbers
class sign_padding :public std::num_put<char> {
public:
// only for float and double
iter_type do_put(iter_type s, std::ios_base& f,
char_type fill, double v) const
{
if (std::signbit(v) == false)
*s++ = ' ';
return std::num_put<char>::do_put(s, f, fill, v);
}
};
int main()
{
// add the facet to std::cout
std::cout.imbue(std::locale(std::cout.getloc(), new sign_padding));
// now print what you want to print
std::cout << -56.0f << "\n"
<< +56.0f << "\n"
<< -0.0f << "\n"
<< +0.0f << "\n";
// output:
// -56
// 56
// -0
// 0
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bG9jYWxlPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Y21hdGg+CgovLyBhIG51bV9wdXQgZmFjZXQgdG8gYWRkIGEgcGFkZGluZyBzcGFjZSBmb3IgcG9zaXRpdmUgbnVtYmVycwpjbGFzcyBzaWduX3BhZGRpbmcgOnB1YmxpYyBzdGQ6Om51bV9wdXQ8Y2hhcj4gewpwdWJsaWM6CiAgICAvLyBvbmx5IGZvciBmbG9hdCBhbmQgZG91YmxlCiAgICBpdGVyX3R5cGUgZG9fcHV0KGl0ZXJfdHlwZSBzLCBzdGQ6Omlvc19iYXNlJiBmLAogICAgICAgICAgICAgICAgICAgICBjaGFyX3R5cGUgZmlsbCwgZG91YmxlIHYpIGNvbnN0CiAgICB7CiAgICAgICAgaWYgKHN0ZDo6c2lnbmJpdCh2KSA9PSBmYWxzZSkKICAgICAgICAgICAgKnMrKyA9ICcgJzsKICAgICAgICByZXR1cm4gc3RkOjpudW1fcHV0PGNoYXI+Ojpkb19wdXQocywgZiwgZmlsbCwgdik7CiAgICB9Cn07CgppbnQgbWFpbigpCnsKCS8vIGFkZCB0aGUgZmFjZXQgdG8gc3RkOjpjb3V0CiAgICBzdGQ6OmNvdXQuaW1idWUoc3RkOjpsb2NhbGUoc3RkOjpjb3V0LmdldGxvYygpLCBuZXcgc2lnbl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