Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. setlocale() doesn't work!

setlocale() doesn't work!

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Green Fuze
    wrote on last edited by
    #1

    Hey everybody I have the following code:

    wstring curlocale1(::_wsetlocale(LC_ALL, NULL));
    printf("+++ current locale: %s", curlocale1.c_str());

    ::_wsetlocale(LC_ALL, L"en_us");

    wstring curlocale2(::_wsetlocale(LC_ALL, NULL));
    printf("+++ current locale: %s", curlocale2.c_str());

    and the output is: +++ current locale: C +++ current locale: C I can't understand why my locale does not change, what am I doing wrong? Thanks a lot!

    L A 2 Replies Last reply
    0
    • G Green Fuze

      Hey everybody I have the following code:

      wstring curlocale1(::_wsetlocale(LC_ALL, NULL));
      printf("+++ current locale: %s", curlocale1.c_str());

      ::_wsetlocale(LC_ALL, L"en_us");

      wstring curlocale2(::_wsetlocale(LC_ALL, NULL));
      printf("+++ current locale: %s", curlocale2.c_str());

      and the output is: +++ current locale: C +++ current locale: C I can't understand why my locale does not change, what am I doing wrong? Thanks a lot!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Used correctly it works fine:

      wstring curlocale1(::\_wsetlocale(LC\_ALL, NULL));
      printf("+++ current locale: %S\\n", curlocale1.c\_str());
      
      ::\_wsetlocale(LC\_ALL, L"English");
      
      wstring curlocale2(::\_wsetlocale(LC\_ALL, NULL));
      printf("+++ current locale: %S\\n", curlocale2.c\_str());
      

      It's time for a new signature.

      G 1 Reply Last reply
      0
      • L Lost User

        Used correctly it works fine:

        wstring curlocale1(::\_wsetlocale(LC\_ALL, NULL));
        printf("+++ current locale: %S\\n", curlocale1.c\_str());
        
        ::\_wsetlocale(LC\_ALL, L"English");
        
        wstring curlocale2(::\_wsetlocale(LC\_ALL, NULL));
        printf("+++ current locale: %S\\n", curlocale2.c\_str());
        

        It's time for a new signature.

        G Offline
        G Offline
        Green Fuze
        wrote on last edited by
        #3

        Hey, thanks :-) But "English" doesn't return "English (United States)", but generic English. Anyway, I found this GREAT article in codeproject that sort some things out, so I'm sitting on that :-) Windows SetThreadLocale and CRT setlocale[^]

        L 1 Reply Last reply
        0
        • G Green Fuze

          Hey, thanks :-) But "English" doesn't return "English (United States)", but generic English. Anyway, I found this GREAT article in codeproject that sort some things out, so I'm sitting on that :-) Windows SetThreadLocale and CRT setlocale[^]

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Green Fuze wrote:

          But "English" doesn't return "English (United States)"

          Try "English_US". I know locales sometimes seem far more complicated than necessary but there are many different combinations to account for.

          It's time for a new signature.

          G 1 Reply Last reply
          0
          • L Lost User

            Green Fuze wrote:

            But "English" doesn't return "English (United States)"

            Try "English_US". I know locales sometimes seem far more complicated than necessary but there are many different combinations to account for.

            It's time for a new signature.

            G Offline
            G Offline
            Green Fuze
            wrote on last edited by
            #5

            It seems that "american_US" in ::setlocale and 1033 for ::SetThreadLocale() done the trick :-) . It is far too complicated than it should've been! Thanks again! :-)

            L 1 Reply Last reply
            0
            • G Green Fuze

              Hey everybody I have the following code:

              wstring curlocale1(::_wsetlocale(LC_ALL, NULL));
              printf("+++ current locale: %s", curlocale1.c_str());

              ::_wsetlocale(LC_ALL, L"en_us");

              wstring curlocale2(::_wsetlocale(LC_ALL, NULL));
              printf("+++ current locale: %s", curlocale2.c_str());

              and the output is: +++ current locale: C +++ current locale: C I can't understand why my locale does not change, what am I doing wrong? Thanks a lot!

              A Offline
              A Offline
              Aescleal
              wrote on last edited by
              #6

              Locales are platform dependent. They're the most irritating bit of the C++ standard as they leave the likes of Redmond and the Penguin crowd to make the decisions. And they're usually different. I'm not surprised that your code is going horribly wrong on another level - using printf %s with a wide character string is a recipe for printing the first character out if I've ever seen one. Cheers, Ash

              1 Reply Last reply
              0
              • G Green Fuze

                It seems that "american_US" in ::setlocale and 1033 for ::SetThreadLocale() done the trick :-) . It is far too complicated than it should've been! Thanks again! :-)

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Green Fuze wrote:

                Thanks again!

                Thank you for leading me down yet another path of learning.

                It's time for a new signature.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups