4

Is there a way to change how boost::program_options formats the default value of the options in the help text of a program_options::options_description (that one can obtains through cout << description)? In particular I have default values which are floats, so the usual decimal-to-binary conversion gives me a help text that looks like --arg (0.100000001) which is quite ugly.

Using cout << setprecision(4) doesn't work because program_options is <<'ing itself the default values to some internal streams to do the formatting first (at least that's what I inferred by looking at the source code), and what gets <<'ed to cout is the resulting string(stream?).

Thanks.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
antony
  • 2,877
  • 4
  • 31
  • 43

1 Answers1

5

Call the two-argument version of default_value. Then you can specify a string version of the value, and that will get printed instead of trying to print the given value with <<.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467