WideCharToMultiByte example

来自http://tunps.com/widechartomultibyte-example

#include <windows.h>
#include <stdio.h>
#include <wchar.h>
#include <string.h>
 
/* string consisting of several Asian characters */
wchar_t wcsString[] = L"\u9580\u961c\u9640\u963f\u963b\u9644";//門阜陀阿阻附
 
int main()
{
 
    size_t wcsChars = wcslen( wcsString);
 
    size_t sizeRequired = WideCharToMultiByte( 950, 0, wcsString, -1,
                                               NULL, 0,  NULL, NULL);
 
    printf( "Wide chars in wcsString: %u\n", wcsChars);
    printf( "Bytes required for CP950 encoding (excluding NUL terminator): %u\n",
             sizeRequired-1);
 
    sizeRequired = WideCharToMultiByte( CP_UTF8, 0, wcsString, -1,
                                        NULL, 0,  NULL, NULL);
    printf( "Bytes required for UTF8 encoding (excluding NUL terminator): %u\n",
             sizeRequired-1);
}

About tunpishuang

just 4 fun·····
This entry was posted in 未分类 and tagged , . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>