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

如下报错,如何解决 In file included from src/SM2.cc:1: In file included from src/SM2.h:3: In file included from incs/gmp.h:34: In file included from /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/iosfwd:99: In file included from /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/__mbstate_t.h:29: /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:141:77: error: use of undeclared identifier 'wcschr' wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcschr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:148:87: error: use of undeclared identifier 'wcspbrk' wchar_t* __libcpp_wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcspbrk(__s1, __s2);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:155:78: error: use of undeclared identifier 'wcsrchr'; did you mean 'wcschr'? wchar_t* __libcpp_wcsrchr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcsrchr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:143:16: note: 'wcschr' declared here const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:162:86: error: use of undeclared identifier 'wcsstr'; did you mean 'wcschr'? wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:145:16: note: 'wcschr' declared here wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:162:86: error: no matching function for call to 'wcschr' wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:145:16: note: candidate disabled: <no message provided> wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:162:93: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'const wchar_t *' wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);} ^~~~ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:145:38: note: passing argument to parameter '__s' here wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);}
06-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值