Setprecision for boost :: program_options

Is there a way to change how boost :: program_options formats the default value for parameters in the help text program_options::options_description (which can be obtained via cout << description )? In particular, I have default values ​​that are floats, so a regular decimal binary conversion gives me a help text that looks like --arg (0.100000001) , which is pretty ugly.

Using cout << setprecision(4) does not work, because program_options << 'itself is the default value for some internal streams for formatting in the first place (at least what I understood by looking at the source code), and what gets << 'ed before cout is the resulting string (stream?).

Thanks.

+4
source share
1 answer

Call the two-parameter version of default_value . Then you can specify the string version of the value and it will be printed instead of trying to print the set value with << .

+5
source

Source: https://habr.com/ru/post/1396743/


All Articles