C ++ setlocale Function

Source: Internet
Author: User
Tags time and date

Setlocale

Configure the region information.

Syntax: char * setlocale (INT category, const char * locale );

Return Value: String

Function types: operating system and environment

Description

This function is used to configure the region information and set the localization information used by the current program. The category parameter has the following options:

* Lc_all includes all the following options.
* The lc_collate configuration string is compared. php has not yet implemented this item.
* Lc_ctype: Specifies the character category and conversion. For example, change all to uppercase strtoupper ().
* Lc_monetary: financial currency configuration. php has not yet been implemented.
* Lc_numeric: specifies the number of digits after the decimal point.
* Lc_time: specifies the time and date format, which is used with strftime.

If the locale parameter is an empty string "", locale of the system environment variable is used. If locale is zero (null), the local configuration is not changed. The current region value is returned. If the system has not yet implemented the configuration, false is returned.

Locales contain information on how to interpret and perform certain input/output and transformation operations taking into consideration location and language specific settings.

Most running environments have certain Locale information set according to the user preferences or localization. but, independently of this system locale, on start, all C programs have the "c" locale set, which is a rather neutral locale with minimal Locale information that allows the result of programs to be predictable. in order to use the default locale set in the environment, this function can be called with "" as the locale parameter.

The Locale set on start is the same as setlocale (lc_all, "C") wocould set.
The entire default locale can be set by calling setlocale (lc_all ,"");

The setting at the beginning of the C program is the same as setlocale (lc_all, "C ").

Use the default settings of the system to call setlocale (lc_all ,"");

The parts of the current locale affected by a call to this function are specified by parameter category.
Return Value
On success, a pointer to a C string identifying the locale currently set for the category. if category is lc_all and different parts of the locale are set to different values, the string returned gives this information in a format which may vary between compiler implementations.

Example

/* Setlocale example */
# Include <stdio. h>
# Include <time. h>
# Include <locale. h>

Int main ()
{
Time_t rawtime;
Struct TM * timeinfo;
Char buffer [80];

Struct lconv * LC;

Time (& rawtime );
Timeinfo = localtime (& rawtime );

Int twice = 0;

Do {
Printf ("locale is: % s/n", setlocale (lc_all, null); // use the null parameter to obtain the current configuration

Strftime (buffer, 80, "% C", timeinfo );
Printf ("date is: % s/n", buffer );

Lc = localeconv ();
Printf ("currency symbol is: % s/n-/N", LC-> currency_symbol );

Setlocale (lc_all ,"");
} While (! Twice ++ );

Return 0;
}

One of the possible outputs when the previous code is run is:

Locale is: c
Date is: 01/15/13:33:47
Currecy symbol is:
-
Locale is: english_united states.1252
Date is: 1/15/07 1:33:47
Currency symbol is: $

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.