#include <winnls.h>
#include <malloc.h>
LPCSTR AnsiToUtf8(LPCSTR Ansi)
{
int WLength = MultiByteToWideChar(CP_ACP, 0, Ansi, -1, NULL, 0);
LPWSTR pszW = (LPWSTR) _alloca((WLength+1) * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, Ansi, -1, pszW, WLength);
int ALength = WideCharToMultiByte(CP_UTF8, 0, pszW, -1, NULL, 0, NULL, NULL);
LPSTR pszA = (LPSTR)_alloca( ALength + 1);
WideCharToMultiByte(CP_UTF8, 0, pszW, -1, pszA, ALength, NULL, NULL);
pszA[ALength] = 0;
return pszA;
}
LPCSTR WcharToUtf8(LPCWSTR szUnicode)
{
int ALength = WideCharToMultiByte(CP_UTF8, 0, szUnicode, -1, NULL, 0, NULL, NULL);
LPSTR pszA = (LPSTR)_alloca( ALength + 1);
WideCharToMultiByte(CP_UTF8, 0, szUnicode, -1, pszA, ALength, NULL, NULL);
pszA[ALength] = 0;
return pszA;
}
LPCSTR Utf8toAnsi( LPCSTR utf8 )
{
int WLength = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, NULL );
LPWSTR pszW = (LPWSTR) _alloca( (WLength + 1) *sizeof(WCHAR) ) ;
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, pszW, WLength );
pszW[WLength] = 0;
int ALength = WideCharToMultiByte(CP_ACP, 0, pszW, -1, NULL, 0, NULL, NULL);
LPSTR pszA = ( LPSTR ) _alloca ( ALength + 1 );
WideCharToMultiByte(CP_ACP, 0, pszW, -1, pszA, ALength, NULL, NULL);
pszA[ALength] = 0;
return pszA;
}
LPCWSTR Utf8toWchar( LPCSTR utf8 )
{
int WLength = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, NULL );
LPWSTR pszW = (LPWSTR) _alloca( (WLength + 1) *sizeof(WCHAR) ) ;
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, pszW, WLength );
pszW[WLength] = 0;
return pszW;
}UTF8 ANSI 相互转换的函数
最新推荐文章于 2023-03-10 11:12:27 发布
本文介绍了一段用于将ANSI字符串转换为UTF8字符串的C++代码,包括从ANSI到UTF8的转换,从宽字符到UTF8的转换,以及从UTF8到ANSI的转换。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Stable-Diffusion-3.5
图片生成
Stable-Diffusion
Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率
1万+

被折叠的 条评论
为什么被折叠?



