-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetlocal
123 lines (53 loc) · 1.43 KB
/
setlocal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifdef __GNUC__
#define CSET_GBK "GBK"
#define CSET_UTF8 "UTF-8"
#define LC_NAME_zh_CN "zh_CN"
// ifdef __GNUC__
#elif defined(_MSC_VER)
#define CSET_GBK "936"
#define CSET_UTF8 "65001"
#define LC_NAME_zh_CN "Chinese_People's Republic of China"
// ifdef _MSC_VER
#endif
#define LC_NAME_zh_CN_GBK LC_NAME_zh_CN "." CSET_GBK
#define LC_NAME_zh_CN_UTF8 LC_NAME_zh_CN "." CSET_UTF8
#define LC_NAME_zh_CN_DEFAULT LC_NAME_zh_CN_GBK
void print_current_loc();
int main(int argc, char* argv[])
{
char* locname = NULL;
const wchar_t* strzh = L"中文字符串";
print_current_loc();
// 使用指定的 locale
locname = setlocale(LC_ALL, LC_NAME_zh_CN_DEFAULT);
if ( NULL == locname )
{
printf("setlocale() with %s failed./n", LC_NAME_zh_CN_DEFAULT);
}
else
{
printf("setlocale() with %s succeed./n", LC_NAME_zh_CN_DEFAULT);
}
print_current_loc();
wprintf(L"Zhong text is: %ls/n", strzh);
// 使用运行环境中的 locale 设置
locname = setlocale(LC_ALL, "");
if ( NULL == locname )
{
printf("setlocale() from environment failed./n");
}
else
{
printf("setlocale() from environment succeed./n");
}
print_current_loc();
wprintf(L"Zhong text is: %ls/n", strzh);
puts("End of program.");
return 0;
}
// 打印当前 locale
void print_current_loc()
{
char* locname = setlocale(LC_ALL, NULL);
printf("Current locale is: %s/n", locname);
}