How can I make boost::lexical_cast include a positive sign when converting to std::string?
I intend to do the same as: snprintf( someArray, someSize, "My string which needs sign %+d", someDigit );
. Here, someDigit would be put in the string as +someDigit if it were positive, or -someDigit if it were negative. See: http://www.cplusplus.com/reference/clibrary/cstdio/snprintf/
There is no way to control the formatting of built-in types when using
boost::lexical_cast<>
.boost::lexical_cast<>
uses streams to do the formatting. Hence, one can create a new class and overloadoperator<<
for it andboost::lexical_cast<>
will use that overloaded operator to format values of the class: