- 论坛徽章:
- 0
|
在WIN上wchar_t是2个字节 Linux上是4个字节
gcc 有选项-fshort-wchar 把wchar_t 编译成2个字节
但用着怎么有问题呢?
test.cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wctype.h>
#include <wchar.h>
using namespace std ;
int main()
{
wchar_t *wcs = L"this";
char a_szDest[50] ;
int count = wcstombs(a_szDest,wcs,50) ;
printf("sizeof(wchar_t)=%d\n",sizeof(wchar_t)) ;
printf("count=%d\n",count);
printf("dest=%s\n",a_szDest);
printf("%d\n",wcslen(wcs)) ;
return 0 ;
}
1、不用选项-fshort-wchar 编译
g++ -o test test.cpp
结果:
sizeof(wchar_t)=4
count=4
dest=this
4
2、用选项编译
g++ -o test test.cpp -fshort-wchar
结果:
sizeof(wchar_t)=2
count=-1
dest=
13
现在 wcslen(wcs)) 怎么成了13
各位大虾们 快帮忙..
谢谢
[ 本帖最后由 迷離 于 2009-1-8 12:08 编辑 ] |
|