// 注意,此文档最好采用utf-8编码
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>
void convert_test(char* src_wstr,wchar_t* dest_str)
{
setlocale(LC_ALL, "zh_CN.UTF-8");
//char* src_str = "中国";
//wchar_t* src_wstr = L"中国";
//char* dest_str = (char *)malloc(32);
//wchar_t* dest_wstr = (wchar_t*)malloc(32);
//mbstowcs(src_wstr, dest_str, mbstowcs(NULL, dest_str, 128));
//wcstombs(dest_str, src_wstr, wcstombs(NULL, src_wstr, 100));
//free(dest_str);
//free(dest_wstr);
}
int main()
{
//此语句重要,在win7 + vs2012和 ubuntu 12.04测试结果一致
//只要打印wchar_t字符,均加此语句,至少不会出错,此语句最好在程序初始化处
//setlocale(LC_ALL, "");
// wprintf和printf最好不能同时使用.
// 如下使用printf同时打印了char字符串和wchar_t字符串
// 因此只采用printf是比较好的方法
//wchar_t ws[] = L"国家";
//printf("printf content start: %ls\n", ws);
//printf("content end\n");
char s[128];
wchar_t ws[] = L"ah";
setlocale(LC_ALL, "zh_CN.UTF-8");
sprintf(s,"%ls",ws);
printf("123\n");
char dst1[128];
wchar_t dst2[128];
memset(dst1,0,128);
memset(dst2,0,sizeof(wchar_t)*128);
memcpy(dst1,s,128);
swprintf(dst2, 128, L"%s", s);
//swprintf(dst2,"%s",s);
//convert_test(s,ws);
printf("abc\n");
wchar_t abc[32] = {0};
char ttt[128] = {0};
printf("size = %d \n",sizeof(abc));
printf("ttt = %d \n",sizeof(ttt));
return 0;
}