|
Boost : |
From: Brey, Edward D (EdwardDBrey_at_[hidden])
Date: 2002-01-29 13:01:07
> From: Karl Nelson [mailto:kenelson_at_[hidden]]
> [MS's String.Format]
> Any pointers to their format string?
The only docs I've seen is that couple paragraphs at the bottom of the page.
I think that is all there is.
> This gets a lot harder when you start throwing in
> manipulators unfortunately.
> That is why I am switching to a groupable format like...
>
> cout << format( fstr, 1.0, group(hex,width(10),16), "bob");
>
> rather than
>
> cout << format(fstr) % 1.0 % hex % width(10) % 16 % "bob" ;
I definitely like the grouping format for local manipulators. For
persistent manipulators, however, it is not appropriate. We need both.
> In the first the positionally nature is there. Plus you can now
> see the manipulators are only to the one argument.
>
> It also is good in that you can group arguments in reasonable ways...
>
> cout << format(" Change is %d", group( c>0?'+':'-', c) );
>
> Thus both the char and the int get placed in the position 1.
Clever idea. I like it.
Only the %d confuses the issue. I would expect the %d to be applied to each
argument, meaning for c=3 you would get: " Change is 433". This is a good
example of why is it best of avoid type specifiers unless you really want to
override the current format specified by the manipulator context (e.g.
override decimal with hex or vice verse).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk