linux 下的 wchar_t



linux 下的 wchar_t


1. 默认情况下,windows 下的 wchar_t 占两个字节的长度,而 linux 下的 wchar_t 占四个字节的长度,可以在使用 gcc 编译程序的时候再后面跟上 -fshort-wchar 来解决这个问题。


2. linux 下 wchar_t* 字符串的输出问题 —— 没有解决。


3. 如下程序,可输出宽字符,但是如果加上 -fshort-wchar 编译选项,则输出为乱码。


[cpp] view plain copy
#include <wchar.h>     
#include <locale.h>     
#include <stdlib.h>     
#include <stdio.h>     
#include <string.h>      
int main(void)      
{      
    setlocale(LC_ALL,"zh_CN.UTF-8");    
    wchar_t a[10] = L"你好";  
    wprintf(L"this is a test !/n");    
    wprintf(L"%d/n",wcslen(a));      
    wprintf(L"%ls/n",a);      
    retur 0;  
}  


4. 可以使用下面这个函数,输出经参数 -fshort-wchar 编译过的宽字符。


[cpp] view plain copy
void print_wcs( const wchar_t *text )  
{  
    int         len = 0;  
    int      i   = 0;  
    wchar_t  *p  = NULL;  
      
    if( NULL == text )  
        return;  
      
    p = text;  
    while( *p != L'/0' )  
        printf( "%lc", *p++ );  

}  


http://blog.youkuaiyun.com/simeone18/article/details/6589504

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值