对于ascii码的char事实上就是unicode码wchar的首个字节码,
如wchar[20] = "qqqq"; 在内存中排码事实上是char的'q' ' '这类。因此我们假设自己写unicode码转换为ascii的char,仅仅须要取其首字节就可以,例如以下本人写了一个wchar到char的转换的函数。
因为代码简单,加上了内存泄露測试方式。
#include <stdio.h>
#ifdef _DEBUG
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#include <tchar.h>
#include <Windows.h>
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif
char* UnicodeToMultibyte(WCHAR *wStr)
{
if (NULL != wStr)
{
int nLen = wcslen(wStr);
char *pStr = new char[nLen + 1];
int i = 0;
for (; i < nLen; ++i)
{
(pStr)[i] = (char)*(wStr + i);
}
(pStr)[i] = '