标签:
01 #ifdef __GNUC__ 02 03 #define CSET_GBK "GBK" 04 #define CSET_UTF8 "UTF-8" 05 06 #define LC_NAME_zh_CN "zh_CN" 07 08 // ifdef __GNUC__ 09 #elif defined(_MSC_VER) 10 11 #define CSET_GBK "936" 12 #define CSET_UTF8 "65001" 13 14 #define LC_NAME_zh_CN "Chinese_People‘s Republic of China" 15 16 // ifdef _MSC_VER 17 #endif 18 19 #define LC_NAME_zh_CN_GBK LC_NAME_zh_CN "." CSET_GBK 20 #define LC_NAME_zh_CN_UTF8 LC_NAME_zh_CN "." CSET_UTF8 21 #define LC_NAME_zh_CN_DEFAULT LC_NAME_zh_CN_GBK 22 23 void print_current_loc(); 24 25 int main(int argc, char* argv[]) 26 { 27 char* locname = NULL; 28 const wchar_t* strzh = L"中文字符串"; 29 30 print_current_loc(); 31 32 // 使用指定的 locale 33 locname = setlocale(LC_ALL, LC_NAME_zh_CN_DEFAULT); 34 if ( NULL == locname ) 35 { 36 printf("setlocale() with %s failed.\n", LC_NAME_zh_CN_DEFAULT); 37 } 38 else 39 { 40 printf("setlocale() with %s succeed.\n", LC_NAME_zh_CN_DEFAULT); 41 } 42 43 print_current_loc(); 44 45 wprintf(L"Zhong text is: %ls\n", strzh); 46 47 // 使用运行环境中的 locale 设置 48 locname = setlocale(LC_ALL, ""); 49 if ( NULL == locname ) 50 { 51 printf("setlocale() from environment failed.\n"); 52 } 53 else 54 { 55 printf("setlocale() from environment succeed.\n"); 56 } 57 58 print_current_loc(); 59 60 wprintf(L"Zhong text is: %ls\n", strzh); 61 62 puts("End of program."); 63 return 0; 64 } 65 66 // 打印当前 locale 67 void print_current_loc() 68 { 69 char* locname = setlocale(LC_ALL, NULL); 70 printf("Current locale is: %s\n", locname); 71 }
标签:
原文地址:http://www.cnblogs.com/danjing/p/4539555.html