字符编码格式的转换

(1)将Unicode转换为UTF8格式:

wchar_t * wsContent =L"";

int nContentLen = WideCharToMultiByte(CP_UTF8, 0, wsContent, -1, NULL, 0, NULL, NULL);

int nLen = nContentLen*sizeof(wchar_t);

char * pCdata = new char[nLen];

int ret = WideCharToMultiByte(CP_UTF8, 0, wsContent, -1, pCdata, nContentLen, NULL, NULL);

(2)将UTF8格式转换为Unicode:

char* pchar = "";

int nUnicodeLen = MultiByteToWideChar(CP_UTF8, 0, pchar, -1, NULL, 0);

wchar_t * pWcdata = new wchar_t[nUnicodeLen + 1];

int ret = MultiByteToWideChar(CP_UTF8, 0, pchar, -1, pWcdata, nUnicodeLen);

(3)将Unicode转换为ANSI格式:

wchar_t * wsContent =L"";

int nContentLen = WideCharToMultiByte(CP_ACP, 0, wsContent, -1, NULL, 0, NULL, NULL);

int nLen = nContentLen*sizeof(wchar_t);

char * pCdata = new char[nLen];

int ret = WideCharToMultiByte(CP_ACP, 0, wsContent, -1, pCdata, nContentLen, NULL, NULL);

(4)将ANSI格式转换为Unicode:

char* pchar = "";

int nUnicodeLen = MultiByteToWideChar(CP_ACP, 0, pchar, -1, NULL, 0);

wchar_t * pWcdata = new wchar_t[nUnicodeLen + 1];

int ret = MultiByteToWideChar(CP_ACP, 0, pchar, -1, pWcdata, nUnicodeLen);

猜你喜欢

转载自blog.csdn.net/yy2yy99/article/details/81559944
今日推荐