clocale header file in C++

clocale: This header file contains declaration of a set of functions and a type for internationalization support tasks. It supports date format or country specific currency symbols.
For example, date/time formatting, monetary formatting and many more.

Methods in clocale header:

  1. localeconv(): This function returns an object which represents numeric and monetary formatting rules of the current C locale. Its corresponding header file is . The “c” locale is the minimal locale. It is a locale which has the same settings across all the compilers, so the result is predictable anyway. By default used on all C programs.

    Prototype



    lconv* localeconv();
    

    Parameters: This method has no parameters.

    Return value: This function returns a pointer to a static object that contains numeric and monetary formatting rules of the current C locale.

    Program:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    #include <iostream>
    #include <locale.h>
    using namespace std;
      
    int main()
    {
        setlocale(LC_MONETARY, "en_US.utf8");
        struct lconv* lc = localeconv();
        printf("%s ", lc->currency_symbol);
        return 0;
    }

    chevron_right

    
    

    Output:

    $
    
  2. setlocale(): The setlocale() function installs the specified system locale. Moreover, it sets the locale information for the current C program. It can also be used to query the current C locale. It has some parameters namely,
    • LC_ALL -> Selects all the C locale
    • LC_NUMERIC -> Selects numeric formatting category
    • LC_MONETARY -> Monetary formatting category
    • LC_CTYPE -> Character classification category
    • LC_TIME -> Time formatting category

    Prototype:

    int setlocale(int category, const char* locale);
    

    Return value: It returns a pointer to the string identifying the C locale after applying the changes. Otherwise, it returns a NULL pointer.

    Program:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    #include <clocale>
    #include <iostream>
    using namespace std;
      
    int main()
    {
        char* s;
        setlocale(LC_ALL, "en_UA.utf8");
        s = setlocale(LC_ALL, NULL);
        cout << s << "\n";
        return 0;
    }

    chevron_right

    
    

    Output:

    C
    


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.