Dev C++ Locale.h

Dev C++ Locale.h Average ratng: 5,0/5 2710 votes
  • The C Standard Library
  1. Locale.h Dev C++
  2. C++ Locale Names
  3. C++ Std Locale
  4. C++ Get Current Locale

19 rows  The locale.h header defines the location specific settings, such as date formats and currency symbols. You will find several macros defined along with an important structure struct lconv and two important functions listed below. Library Macros. Following are the macros defined in the header and these macros will be used in two functions listed below −. Include the standard header to alter or access properties of the current locale- a collection of culture-specific information.An implementation can define additional macros in this standard header with names that begin with LC.You can use any of these macro names as the locale category argument (which selects a cohesive subset of a locale) to setlocale. Sep 02, 2007  Problems Compiling Dev C 4.9.9.2. C / C Forums on Bytes. Post your question and get tips & solutions from a community of 449,177 IT Pros & Developers.

  • (Set Locale) In the C Programming Language. #include Applies To. In the C Language, the setlocale function can be used in the following versions: ANSI/ISO 9899-1990. We use advertisements to support this website and fund the development of new content.
  • 7.4 How Programs Set the Locale. A C program inherits its locale environment variables when it starts up. This happens automatically. However, these variables do not automatically control the locale used by the library functions, because ISO C says that all programs start by default in the standard ‘C’ locale.To use the locales specified by the environment, you must call setlocale.
  • Returns the name of the locale, in an implementation-specific manner. If the locale has no name, the function returns '.'. Constructing a new locale object with the value returned by this function (if this is different from '.') creates a locale with the same properties as.this.
  • I am using two functions sprintf and snprintf for dealing with conversions of 'double' to string, In one of the case, the application which is running has a different locale than the Windows' local.
  • C Standard Library Resources
  • C Programming Resources
  • Selected Reading

The locale.h header defines the location specific settings, such as date formats and currency symbols. You will find several macros defined along with an important structure struct lconv and two important functions listed below.

Library Macros

Following are the macros defined in the header and these macros will be used in two functions listed below −

C++ std locale
Sr.No.Macro & Description
1

LC_ALL

Sets everything.

2

LC_COLLATE

Affects strcoll and strxfrm functions.

3

LC_CTYPE

Affects all character functions.

4

LC_MONETARY

Affects the monetary information provided by localeconv function.

5

LC_NUMERIC

Affects decimal-point formatting and the information provided by localeconv function.

6

LC_TIME

Affects the strftime function.

Library Functions

Following are the functions defined in the header locale.h −

Sr.No.Function & Description
1char *setlocale(int category, const char *locale)

Sets or reads location dependent information.

2struct lconv *localeconv(void)

Sets or reads location dependent information.

Library Structure

Following is the description of each of the fields −

Locale.h Dev C++

Sr.No.Field & Description
1

decimal_point

Decimal point character used for non-monetary values.

2

thousands_sep

Thousands place separator character used for non-monetary values.

3

grouping

A string that indicates the size of each group of digits in non-monetary quantities. Each character represents an integer value, which designates the number of digits in the current group. A value of 0 means that the previous value is to be used for the rest of the groups.

4

int_curr_symbol

It is a string of the international currency symbols used. The first three characters are those specified by ISO 4217:1987 and the fourth is the character, which separates the currency symbol from the monetary quantity.

5

currency_symbol

The local symbol used for currency.

6

mon_decimal_point

The decimal point character used for monetary values.

7

mon_thousands_sep

The thousands place grouping character used for monetary values.

8

mon_grouping

A string whose elements defines the size of the grouping of digits in monetary values. Each character represents an integer value which designates the number of digits in the current group. A value of 0 means that the previous value is to be used for the rest of the groups.

9

positive_sign

The character used for positive monetary values.

Presonus studio one 4.5.1 update windows 7

10

negative_sign

The character used for negative monetary values.

11

int_frac_digits

Number of digits to show after the decimal point in international monetary values.

12

frac_digits

Number of digits to show after the decimal point in monetary values.

13

p_cs_precedes

If equals to 1, then the currency_symbol appears before a positive monetary value. If equals to 0, then the currency_symbol appears after a positive monetary value.

14

p_sep_by_space

If equals to 1, then the currency_symbol is separated by a space from a positive monetary value. If equals to 0, then there is no space between the currency_symbol and a positive monetary value.

15

n_cs_precedes

If equals to 1, then the currency_symbol precedes a negative monetary value. If equals to 0, then the currency_symbol succeeds a negative monetary value.

16

n_sep_by_space

If equals to 1, then the currency_symbol is separated by a space from a negative monetary value. If equals to 0, then there is no space between the currency_symbol and a negative monetary value.

17

p_sign_posn

Represents the position of the positive_sign in a positive monetary value.

18

n_sign_posn

Represents the position of the negative_sign in a negative monetary value.

The following values are used for p_sign_posn and n_sign_posn

ValueDescription
0Parentheses encapsulates the value and the currency_symbol.
1The sign precedes the value and currency_symbol.
2The sign succeeds the value and currency_symbol.
3The sign immediately precedes the value and currency_symbol.
4The sign immediately succeeds the value and currency_symbol.
  • The C Standard Library
  • C Standard Library Resources
  • C Programming Resources
  • Selected Reading

C++ Locale Names

Description

The C library function char *setlocale(int category, const char *locale) sets or reads location dependent information.

Declaration

C++

C++ Std Locale

Following is the declaration for setlocale() function.

Parameters

  • category − This is a named constant specifying the category of the functions affected by the locale setting.

    • LC_ALL for all of the below.

    • LC_COLLATE for string comparison. See strcoll().

    • LC_CTYPE for character classification and conversion. For example − strtoupper().

    • LC_MONETARY for monetary formatting for localeconv().

    • LC_NUMERIC for decimal separator for localeconv().

    • LC_TIME for date and time formatting with strftime().

    • LC_MESSAGES for system responses.

  • locale − If locale is NULL or the empty string ', the locale names will be set from the values of environment variables with the same names as the above categories.

Return Value

A successful call to setlocale() returns an opaque string that corresponds to the locale set. The return value is NULL if the request cannot be honored.

Example

The following example shows the usage of setlocale() function.

C++ Get Current Locale

Let us compile and run the above program that will produce the following result −

locale_h.htm