CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2010
    Posts
    105

    Question stringstream << version of sprintf with variable precision?

    I would like to rewrite something like
    Code:
    sprintf(str, "%d, %.1lf, %.3lf, %.2lf, ...", a, b, c, d, ....)
    to something like
    stringstream str<<a<<fixed<<b<<c<<d ...
    But is there a way to specify varying precision easily (there are about 100 values to be converted to a string with varying precisions.)? Something like
    Code:
    ... <<%.1<<b<<%.3<<c<<%.2<<d ...
    Possible? If so then what's the syntax? Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: stringstream << version of sprintf with variable precision?

    You could look into Boost.Format.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Aug 1999
    Location
    Darmstadt, FRG
    Posts
    87

    Re: stringstream << version of sprintf with variable precision?

    setprecision() may help. Consider to include <iomanip>.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured