[疑难] 原来Phobos的setlocale()是调用的DMC++的库

catdog 2008-11-01
PHOBOS输出汉字是有问题的~网上只有一种解决方案:
   1. import std.stdio;  
   2.   
   3. private import std.c.stdio;  
   4. extern(C) int setlocale(int, char*);  
   5. static this() {  
   6.     fwide(stdout, 1);  
   7.     setlocale(0, "china");  //zh_cn.utf8,zh_cn.gb2312都不管用~
   8. }  
   9.   
  10. int main()  
  11. {  
  12.     writef("你好, D!");  
  13.     return 0;  
  14. }  

但是按照C的标准应该是写成zh_cn.utf8之类的形式,但是不管用~只有写成china才能正确输出中文~~一直想不通为什么,直到昨天发现Digital Mars原来还有个C/C++的编译器,就去看了一下它的locale.h的文档:http://www.digitalmars.com/rtl/locale.html#setlocale里面有这么一段:
引用
The following locales are recognized:

Locale/Description
C
    The minimal default locale.
USA
    Predefined in locale.h as the "native" locale. setlocale(LC_ALL,"") selects this.

It also recognizes Italy, Netherlands, Norway, Switzerland, UK, Japan, Korea, China.

Information about the current locale can be obtained by calling setlocale with a NULL second argument. This will return the current locale for the category selected. Having set the locale, a call to localeconv will obtain a pointer to a filled in struct lconv with the specific locale values. See localeconv for details.


我估计DMD用的locale是DMC++的,才会出现这种情况。。。。。。

不过还有个问题:fwide()为啥非要设置成1,我设置成2,3都可以,0就不行~而且printf还是始终不行~
tomqyp 2008-11-01
phobos以前用的是c runtime,现在是不是用druntime还没有研究过。

中文问题以前论坛里有过讨论搜索一下。

fwide是设置io操作时的字符宽度,是个BOOL值,0为CHAR, 非0为WCHAR
Global site tag (gtag.js) - Google Analytics