Skip to content

Commit 9049320

Browse files
authored
Merge pull request #61 from Xushi8/fix-setlocale
fix setlocale bug on unicode.md
2 parents eb787cd + 8bbdd3c commit 9049320

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

docs/unicode.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -2848,11 +2848,13 @@ int main() {
28482848
setlocale(LC_ALL, ".utf-8"); // 设置标准库调用系统 API 所用的编码,用于 fopen,ifstream 等函数
28492849
SetConsoleOutputCP(CP_UTF8); // 设置控制台输出编码,或者写 system("chcp 65001") 也行,这里 CP_UTF8 = 65001
28502850
SetConsoleCP(CP_UTF8); // 设置控制台输入编码,用于 std::cin
2851+
#elif __APPLE__
2852+
// 通常来说 MacOS 的默认编码就是 UTF-8,这里设置全局 locale 是为了让 iswspace 接受全角空格、iswpunct 接受全角逗号 L',' 等
2853+
setlocale(LC_ALL, "UTF-8"); // MacOS 设置 UTF-8 编码,让 iswspace 接受全角空格等
28512854
#elif __unix__
28522855
// 反正 Unix 系统默认都是 UTF-8,不设置也行,这里设置全局 locale 是为了让 iswspace 接受全角空格、iswpunct 接受全角逗号 L',' 等
28532856
//setlocale(LC_ALL, "zh_CN.utf-8"); // 设置使用中文本地化,可使 strerror 输出中文(但用户必须 locale-gen 过中文!)
2854-
//setlocale(LC_ALL, "C.utf-8"); // 设置使用语言中性 locale,只影响 iswspace、iswpunct 等函数,不会使 strerror 等输出中文
2855-
setlocale(LC_ALL, ".utf-8"); // 若不带任何前缀(推荐),则默认使用当前系统环境变量中的语言 $LANG,使 strerror 自动适应
2857+
setlocale(LC_ALL, "C.utf-8"); // 设置使用语言中性 locale(推荐),只影响 iswspace、iswpunct 等函数,不会使 strerror 等输出中文
28562858
#endif
28572859
// 这里开始写你的主程序吧!
28582860
// ...

0 commit comments

Comments
 (0)