WideCharToMultiByte:Unicode转char *(宽字节转多字节)
MSDN:[url]http://msdn.microsoft.com/en-us/library/dd374130(VS.85).aspx[/url]
MultiByteToWideChar:char *转Unicode(多字节转宽字节)
MSDN:[url]http://msdn.microsoft.com/en-us/library/dd319072(VS.85).aspx[/url]
MSDN:[url]http://msdn.microsoft.com/en-us/library/dd374130(VS.85).aspx[/url]
#include "stdafx.h"
#include "stdio.h"
#include "windows.h"
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR strWideChar[] = _T("zerosoul"); //Unicode宽字节编码字符串strWideChar
//获得转换后的字符串长度n_len
int n_len = WideCharToMultiByte(CP_ACP,NULL,strWideChar,-1,NULL,0,NULL,NULL);
char* strMultiByte = new char[n_len]; //ANSI多字节编码字符串strMultiByte
WideCharToMultiByte(CP_ACP,NULL,strWideChar,-1,strMultiByte,n_len,NULL,NULL); //开始转换
printf("strMultiByte : %s\n",strMultiByte);
return 0;
}
MultiByteToWideChar:char *转Unicode(多字节转宽字节)
MSDN:[url]http://msdn.microsoft.com/en-us/library/dd319072(VS.85).aspx[/url]
#include "stdafx.h"
#include "stdio.h"
#include "windows.h"
int _tmain(int argc, _TCHAR* argv[])
{
char strMultiByte[] = "zerosoul"; //ANSI多字节编码字符串strMultiByte
//获得转换后的字符串长度n_len
int n_len = MultiByteToWideChar(CP_ACP,NULL,strMultiByte,-1,NULL,0);
TCHAR* strWideChar = new TCHAR[n_len]; //Unicode宽字节编码字符串strWideChar
MultiByteToWideChar(CP_ACP,NULL,strMultiByte,-1,strWideChar,n_len); //开始转换
_tprintf(_T("strWideChar : %s\n"),strWideChar);
return 0;
}