#111 setlocale fails with c++ cin and cout


I am working with w32api 1.2. I am using the setlocale
function (from locale.h) to change the decimal_point
behavior of cin and cout in C++. This doensn't work.
However, on Linux (suse 7.3), I have setlocale working
with cin and cout.

After some testing with w32api, I found that setlocale
only works for scanf and printf functions. In
addition, language-strings which setlocale accepts are
different for Linux and w32api. With Linux, "en_US"
and "nl_NL" are accepted. With w32api, these are not
accepted, but "nld" and "usa" are accepted.

Executing the following code shows the problem:
setlocale(LC_ALL, "nld");
cout << "after nld : setlocale = " << setlocale
(LC_ALL, NULL) << endl;
cout << "cout: x= " << (float)1234/3 << endl;
printf("printf: x= %f\n", (float)1234/3);

setlocale(LC_ALL, "usa");
cout << "after usa : setlocale = " << setlocale
(LC_ALL, NULL) << endl;
cout << "cout: x= " << (float)1234/3 << endl;
printf("printf: x= %f\n", (float)1234/3);

How can I get it working?

Thanks in advance, Alexander


  • Danny Smith

    Danny Smith - 2002-02-02

    Logged In: YES

    In libstdc++, only C-locale is currently supported under
    mingw in iostream classes. setlocale changes the setting of
    the current active locale. It doesn't affect the static
    global C-locale.

    The language strings accepted by setlocale are outside
    mingw's control. They are determined by the MS runtime,
    which supplies setlocale.

  • Earnie Boyd

    Earnie Boyd - 2002-08-05
    • status: open --> closed-out-of-date
  • Earnie Boyd

    Earnie Boyd - 2013-01-25
    • labels: w32api (deprecated use WSL) -->
    • status: closed-out-of-date --> closed
    • resolution: --> out-of-date
    • category: --> User_Error
    • milestone: --> WSL

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks