windows下utf-8转为unicode并打印输出

来源:互联网 发布:同花顺直播软件 编辑:程序博客网 时间:2024/06/09 23:30
                                             windows下utf-8转为unicode并打印输出

首先把utf-8转为unicode

实例:
    // 求出rsps->clientid的长度
    nLenW = MultiByteToWideChar(CP_UTF8, 0,(LPCSTR)rsps->clientid, -1, NULL, 0);
    // 申请空间
    wszBuf = malloc(sizeof(WCHAR) * (nLenW + 1));
    memset(wszBuf, 0, sizeof(WCHAR) * (nLenW + 1));
    //    转换到wszBuf中
    MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)rsps->clientid, -1, wszBuf,nLenW);

其次打印输出
实例:
    // 把wszBuf的内容打印到控制台
    WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE),wszBuf,wcslen(wszBuf),&ws,NULL);


参考:
http://topic.csdn.net/u/20110825/10/67fca50f-0a74-463e-9739-43d318df0ae5.html
http://zhouruijun163.blog.163.com/blog/static/1077156200851593114993/