Re: Doubles and Integers as strings.
"David Wilkinson" <no-reply@effisols.com> wrote in message
news:uYkda4zfHHA.1252@TK2MSFTNGP04.phx.gbl...
P.J. Plauger wrote:
"Alexander Grigoriev" <alegr@earthlink.net> wrote in message
news:uU2F6dufHHA.284@TK2MSFTNGP05.phx.gbl...
iostream formatting is simply ugly. And it's not localizeable.
Uh, yes it is. That's what imbue is for.
Neither is *printf, though,
Uh, yes it is. That's what setlocale is for.
I think that what Alexander means is that you can localize printf by
localizing the format string.
Could be. Absent a widely shared definition of what "localizeable"
might mean, I could also guess that he meant "what's provided by the
Standard C and C++ libraries in the way of locale control."
This allows you to take care of situations
where different languages place the elemnts of a sentence in a different
order. E.g.
25 is a number. (English)
A NUMBER 25 IS. (CAPITALESE)
int n=25;
printf("%d is a number.", n);
printf("A NUMBER %d IS.", n);
By loading the format string from a localizable resource, you can
translate your application without changing the source code. You cannot do
this with iostreams.
But you can do:
cout << PREFIX_STRING << n << SUFFIX_STRING;
and achieve the same effect. And this you can handle in C++ with
much the same locale machinery as in C.
More important, neither printf nor iostreams deals with the highly
related problem that two or more variables might appear in different
order in different languages. (There's a Posix extension to printf
that lets you deal with this in the format string, but it's not yet
a part of Standard C.) So printf has hardly any advantage over
iostreams in this regard.
[Everything I know about localization (which is pretty much limited to the
above observation) I learned from Mihai Nita.]
Localization is a bottomless pit of complexity that is only weakly
supported by standard libraries. IMO, both C and C++ would have been
better off omitting locales completely. And I say this as an implementer
who has done the whole job from stem to stern, and would love to recoup
that investment.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com