Thank you for your reply!
I tried following code: test.nim:
proc setlocale(category: cint; locale: cstring): cstring {.header: "<locale.h>".}
var LC_ALL {.header: "<locale.h>".}: cint
echo setlocale(LC_ALL, "")
stdout.write("ああ\n")
testcpp.nim:
proc setlocale(category: cint; locale: cstring): cstring {.header: "<clocale>", importc: "std::setlocale".}
var LC_ALL {.header: "<clocale>".}: cint
echo setlocale(LC_ALL, "")
stdout.write("ああ\n")
Output:
f:\temp>nim c -r test.nim
....
Hint: f:\temp\test.exe [Exec]
Japanese_Japan.932
ああ
f:\temp>nim cpp -r testcpp.nim
....
Hint: f:\temp\testcpp.exe [Exec]
Japanese_Japan.932
������
Both c and cpp code are initialized with locale Japanese_Japan.932. My cmd.exe's default code page is 932, but code page was changed to 65001 before I ran test codes. And Nim write "ああ" as utf8 with fprintf. It seems locale is not related to this problem.