I am using std::ostringstream to format a double to a string with a specific format (using apostrophes as thousands separators). However, in some cases ostringstream gave me a different result from what I expected.
As far as I can tell, the expected output of the code below should be "+01"; instead it outputs "0+1". What am I doing wrong here, and how can I get the result I need?
#include <iomanip>
#include <iostream>
#include <sstream>
int main()
{
std::ostringstream stream;
stream << std::showpos; // Always show sign
stream << std::setw(3); // Minimum 3 characters
stream << std::setfill( '0' ); // Zero-padded
stream << 1; // Expected output: "+01"
std::cout << stream.str(); // Output: "0+1"
return 0;
}