转换思路如下
1.ANSI先转成UNICODE
2.UNICODE转成UTF8
下面代码是直接由UNICODE转为UTF8编码
1.ANSI先转成UNICODE
2.UNICODE转成UTF8
下面代码是直接由UNICODE转为UTF8编码
- </pre><pre name="code" class="cpp">#include "tchar.h"
- #include "stdio.h"
- #include "windows.h"
- void main()
- {
- WCHAR szStr[]=_T("中国");
- int u8Len=WideCharToMultiByte(CP_UTF8,NULL,szStr,wcslen(szStr),NULL,0,NULL,NULL);
- char * szU8=new char[u8Len+1];
- WideCharToMultiByte(CP_UTF8,NULL,szStr,wcslen(szStr),szU8,u8Len,NULL,NULL);
- szU8[u8Len]='\0';
- printf(szU8);
- }