Previous ArticleArticleMedium, the wide character set to print Chinese characters, also need to set locale
There are not many locale. H files, and the source code of the header file is attached.
View code
/* * ** Locale. h-Definitions/declarations for localization routines ** copyright (c) Microsoft Corporation. all rights reserved. ** purpose: * this file defines the structures, values, macros, and functions * used by the localization routines. ** [public] ***** */ # Pragma Once # Ifndef _ inc_locale # Define _ Inc_locale # Include <Crtdefs. h>/* * Currently, all ms c compilers for Win32 platforms default to 8 byte * alignment. */ # Pragma Pack (push, _ crt_packing) # Ifdef _ cplusplus Extern " C " { # Endif /* Define NULL pointer Value */ # Ifndef null # ifdef _ cplusplus # Define Null 0 # Else # Define NULL (void *) 0) # Endif # Endif /* Locale categories */ # Define Lc_all 0 # Define Lc_collate 1 # Define Lc_ctype 2 # Define Lc_monetary 3 # Define Lc_numeric 4# Define Lc_time 5 # Define Lc_min lc_all # Define Lc_max lc_time /* Locale Convention Structure */ # Ifndef _ lconv_defined Struct Lconv { Char * Decimal_point; Char * Thousands_sep; Char * Grouping; Char * Int_curr_symbol; Char * Currency_symbol; Char * Mon_decimal_point; Char * Mon_thousands_sep; Char * Mon_grouping; Char *Positive_sign; Char * Negative_sign; Char Int_frac_digits; Char Frac_digits; Char P_cs_precedes; Char P_sep_by_space; Char N_cs_precedes; Char N_sep_by_space; Char P_sign_posn; Char N_sign_posn; wchar_t * _ W_decimal_point; wchar_t * _ W_thousands_sep; wchar_t * _ W_int_curr_symbol; wchar_t * _ W_currency_symbol; wchar_t * _ W_mon_decimal_point; wchar_t * _ W_mon_thousands_sep; wchar_t * _ W_positive_sign; wchar_t *_ W_negative_sign ;}; # Define _ Lconv_defined # Endif /* ANSI: Char lconv Members default is char_max which is compile time dependent. Defining and using _ charmax here causes CRT startup code to initialize lconv members properly */ # Ifdef _ char_unsigned Extern Int _ Charmax; Extern _ Inline Int _ Dummy (Void ){ Return _ Charmax ;} # Endif /* Function prototypes */ # Ifndef _ config_locale_swt # Define _ Enable_per_thread_locale 0x1 # Define _ Disable_per_thread_locale 0x2 # Define _ Enable_per_thread_locale_global 0x10 # Define _ Disable_per_thread_locale_global 0x20# Define _ Enable_per_thread_locale_new 0 0x100 # Define _ Disable_per_thread_locale_new 0 0x200 # Define _ Config_locale_swt # Endif _ Check_return_opt _ cribd Int _ Cdecl _ configthreadlocale (_ in _ Int _ Flag); _ check_return_opt _ crqp Char * _ Cdecl setlocale (_ in _ Int _ Category, _ in_opt_z _ Const Char * _ Locale); _ check_return_opt _ cribd Struct Lconv * _ cdecl localeconv ( Void ); _ Check_return_opt _ cribd _ locale_t _ cdecl _ get_current_locale ( Void ); _ Check_return_opt _ cribd _ locale_t _ cdecl _ create_locale (_ in _ Int _ Category, _ in_z _ Const Char * _ Locale); _ cribd Void _ Cdecl _ free_locale (_ in_opt _ locale_t _ locale ); /* Use _ get_current_locale, _ create_locale and _ free_locale, instead of these functions with double leading underscore */ _ Check_return _ crt_obsolete (_ get_current_locale) _ cribd _ locale_t _ cdecl _ get_current_locale ( Void ); _ Check_return _ crt_obsolete (_ create_locale) _ cribd _ locale_t _ cdecl _ create_locale (_ in _ Int _ Category, _ in_z _ Const Char * _ Locale); _ crt_obsolete (_ free_locale) _ cribd Void _ Cdecl _ free_locale (_ in_opt _ locale_t _ locale); # ifndef _ wlocale_defined /* Wide function prototypes, also declared in wchar. h */ _ Check_return_opt _ cribd wchar_t * _ Cdecl _ wsetlocale (_ in _ Int _ Category, _ in_opt_z _ Const Wchar_t * _ Locale ); # Define _ Wlocale_defined # Endif # Ifdef _ cplusplus} # Endif # Pragma Pack (POP) # Endif /* _ Inc_locale */
For more information about how to set locale to print Chinese Characters in wprintf, see:
Http://topic.csdn.net/u/20120331/18/0e806bd0-28d4-4012-9a32-ab99cc16e554.html
(Csdn is annoying in some places)
Obtain the current locale
// In crtdef. h Struct Threadlocaleinfostruct; Struct Threadmbcinfostruct; typedef Struct Threadlocaleinfostruct * Pthreadlocinfo; typedef Struct Threadmbcinfostruct * Pthreadmbcinfo; Struct _ Lc_time_data; typedef Struct Localeinfo_struct {pthreadlocinfo locinfo; pthreadmbcinfo mbcinfo;} _ locale_tstruct, * _ Locale_t; // _ Locale_t ret = _ Get_current_locale (); _ free_locale (RET );
Typedef Struct Threadlocaleinfostruct { Int Refcount; unsigned Int Lc_codepage; unsigned Int Lc_collate_cp; unsigned Long Lc_handle [ 6 ]; /* Lcid */ Lc_id [ 6 ]; Struct { Char * Locale; wchar_t * Wlocale; Int * Refcount; Int * Wrefcount;} lc_category [ 6 ]; Int Lc_clike; Int Mb_cur_max; Int *Lconv_intl_refcount; Int * Lconv_num_refcount; Int * Lconv_mon_refcount; Struct Lconv * Lconv; Int * Ctype1_refcount; unsigned Short * Ctype1; Const Unsigned Short *Pctype; Const Unsigned Char * Pclmap; Const Unsigned Char * Pcumap; Struct _ Lc_time_data * Lc_time_curr;} threadlocinfo;
Threadmbcinfostruct is not found yet.
You do not know how to print the locale represented by the _ locale_t pointer.
Setlocale Return Value
Char*Old_locale; old_locale= Setlocale (lc_all,""); // Setlocale (lc_ctype, null); printf ("Old locale was: \ n % s \ n", Old_locale );
Set locale
Setlocale (lc_ctype,"CHS");//The followingCodeThe meaning is not clear.Tchar szacp [16]; Wsprintf (szacp, _ T (". % D"), Getacp (); _ tsetlocale (lc_ctype, szacp); setlocale (lc_ctype,"");
It is not very useful.
You only need to know how wprintf outputs Chinese characters.