> > I was working with a co-worker the other day to work through the
> > process of formatting numeric values by imbueing C++ iostreams with
[quoted text clipped - 7 lines]
> > Portuguese in our case). We found that, if we removed the above
> > mentioned call that the iostream formatting worked aas we expected.
My
> > question is whether this interaction is a bug or is it rather an
> > unfortunate but planned side effect that comes from mixing the "C"
[quoted text clipped - 15 lines]
>
> Moving the setlocale call to the start makes no difference. The C and
> C++ locale systems are synchronized to a degree. See
http://www.dinkumware.com/manuals/reader.aspx?b=p/&h=locale2.html#locale
> for some info on this, or check the C++ standard.
>
> Tom
I just tried the following code:
#include <iostream>
#include <locale.h>
int main()
{
double const val = 123456.789;
setlocale(LC_ALL,"");
std::cout.imbue(std::locale("Portuguese_Brazil"));
std::cout << val << std::endl;
return 0;
} // main
This produces the behaviour that I described provided that the
operating system regional settings are set to Brasilian Portuguese. It
does not appear when the regional locale is set to US English.
Commenting out the setlocale() call produces the correct behaviour.
Regards,
Jon Trauntvein
Tom Widmer - 16 Mar 2005 19:37 GMT
> I just tried the following code:
> #include <iostream>
> #include <locale.h>
[quoted text clipped - 13 lines]
> does not appear when the regional locale is set to US English.
> Commenting out the setlocale() call produces the correct behaviour.
Ok, I managed to get the same behaviour. Note that changing:
setlocale(LC_ALL,"");
to
std::locale::global(std::locale(""));
gives the same effect without using the C library.
Fiddling around with the regional settings and the code, I didn't work
out the the logic behind the way it works (or, rather, doesn't work).
I'd recommend just removing the call to setlocale if at all possible.
Further, I'd recommend posting in microsoft.public.vc.stl, where
P.J.Plauger and Pete Becker (both of Dinkumware, the standard library
supplier for VC) are likely to see it, and hopefully tell you how it
works, and how to fix your problem.
Tom