Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8450315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:56:13+00:00 2026-06-10T10:56:13+00:00

Had tried following code in Linux, but always return ‘C’ under different LANG settings.

  • 0

Had tried following code in Linux, but always return ‘C’ under different LANG settings.

#include <iostream>
#include <locale.h>
#include <locale>
using namespace std;

int main()
{
    cout<<"locale 1: "<<setlocale(LC_ALL, NULL)<<endl;
    cout<<"locale 2: "<<setlocale(LC_CTYPE, NULL)<<endl;

    locale l;
    cout<<"locale 3: "<<l.name()<<endl;
}

$ ./a.out
locale 1: C
locale 2: C
locale 3: C
$
$ export LANG=zh_CN.UTF-8
$ ./a.out
locale 1: C
locale 2: C
locale 3: C

What should I do to get current locale setting in Linux(like Ubuntu)?

Another question is, is it the same way to get locale in Windows?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:56:15+00:00Added an answer on June 10, 2026 at 10:56 am

    From man 3 setlocale (New maxim: “When in doubt, read the entire manpage.”):

    If locale is "", each part of the locale that should be modified is set according to the environment variables.

    So, we can read the environment variables by calling setlocale at the beginning of the program, as follows:

    #include <iostream>
    #include <locale.h>
    using namespace std;
    
    int main()
    {
        setlocale(LC_ALL, "");
        cout << "LC_ALL: " << setlocale(LC_ALL, NULL) << endl;
        cout << "LC_CTYPE: " << setlocale(LC_CTYPE, NULL) << endl;
        return 0;
    }
    

    My system does not support the zh_CN locale, as the following output reveals:

    $ ./a.out 
    LC_ALL: en_US.utf8
    LC_CTYPE: en_US.utf8
    $ export LANG=zh_CN.UTF-8
    $ ./a.out 
    LC_ALL: C
    LC_CTYPE: C
    

    Windows: I have no idea about Windows locales. I suggest starting with an MSDN search, and then opening a separate Stack Overflow question if you still have questions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had more database and I tried to make backup for them but they
i have tried looking online but had no luck, How i could delete all
I've tried in 2 forums, but I had no luck so far. So, I
i tried the following code for cloning the object. while compiling it shows clone
I had tried the code below in Mathematica 8: f[z_] := (5 + 1/(z-a))
I am learning jQuery and as part of that i tried following code.. It
I tried following code to print rupee symbol; Firefox : <rs><span style=position:absolute;margin-top:-5px>_</span>&#2352;</rs> <br />
I need a simple messagebox in asp.net, I tried the following code. Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), clientScript,<script>javascript:alert('Guest
I was wondering if anyone had any suggestions on improving the following code (if
Using the following code I am getting the text.label but not the detailTextLabel.text. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.