当前位置:网站首页>Utf8 to STD: string and STD: string to utf8
Utf8 to STD: string and STD: string to utf8
2022-04-23 05:30:00 【Oriental forgetfulness】
// UTF8 turn std:string
// The conversion process : First the utf8 Double byte Unicode code , Re pass WideCharToMultiByte Convert wide characters to multibytes .
std::string UTF8_To_string(const std::string& str)
{
int nwLen = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0);
wchar_t* pwBuf = new wchar_t[nwLen + 1]; // Be sure to add. 1, Or there will be a tail
memset(pwBuf, 0, nwLen * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), pwBuf, nwLen);
int nLen = WideCharToMultiByte(CP_ACP, 0, pwBuf, -1, NULL, NULL, NULL, NULL);
char* pBuf = new char[nLen + 1];
memset(pBuf, 0, nLen + 1);
WideCharToMultiByte(CP_ACP, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL);
std::string strRet = pBuf;
delete []pBuf;
delete []pwBuf;
pBuf = NULL;
pwBuf = NULL;
return strRet;
}
// std:string turn UTF8
std::string string_To_UTF8(const std::string& str)
{
int nwLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
wchar_t* pwBuf = new wchar_t[nwLen + 1]; // Be sure to add. 1, Or there will be a tail
ZeroMemory(pwBuf, nwLen * 2 + 2);
::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), pwBuf, nwLen);
int nLen = ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL);
char* pBuf = new char[nLen + 1];
ZeroMemory(pBuf, nLen + 1);
::WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL);
std::string strRet(pBuf);
delete []pwBuf;
delete []pBuf;
pwBuf = NULL;
pBuf = NULL;
return strRet;
}
版权声明
本文为[Oriental forgetfulness]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220543306858.html
边栏推荐
- Solve the problem of JS calculation accuracy
- egg测试的知识大全--mock、superTest、coffee
- Getting started with varnish
- es6数组的使用
- Data bus realizes the communication between brother components
- MFC implementation resources are implemented separately by DLL
- Cmake basic tutorial (39) pkgconfig
- Laravel routing settings
- Camera imaging + homography transformation + camera calibration + stereo correction
- Laravel routing job
猜你喜欢
Uncle wolf is looking for a translator -- Plato -- ongoing translation
Three methods of list rendering
2021-10-12
Nécessité de précharger les cookies dans le sélénium
Excel 2016 打开文件第一次打不开,有时空白,有时很慢要打开第二次才行
弘玑Cyclone RPA为国金证券提供技术支撑,超200个业务场景实现流程自动化
C# ,类库
On the use of constant pointer and pointer constant -- exercise (record)
Understand the relationship between promise async await
Three 之 three.js (webgl)简单实现根据点绘制线/弧线(基于LineGeometry / Line2 / LineMaterial,绘制两点基于圆心的弧线段)
随机推荐
[the background color changes after clicking a line]
catkin_ What did package do
egg中的多进程模型--egg文档搬运工
The 2021 IT industry project management survey report was released!
MFC implementation resources are implemented separately by DLL
创建进程内存管理copy_mm - 进程与线程(九)
The annual transaction volume of the app store is US $1 million, and only 15% commission is paid. Small and medium-sized developers are very contradictory
Call the interface to get the time
Formal parameters, local variables and local static variables
Cmake basic tutorial (39) pkgconfig
Differences between auto and decltype inference methods (learning notes)
JS time format conversion
Note: unordered_ Understanding and use of map
(11) Vscode code formatting configuration
双击.jar包无法运行解决方法
Quick app bottom navigation bar
The main difference between pointer and reference
可执行程序执行流程
Several examples of pointer transfer, parameter transfer, value transfer, etc
Processus d'exécution du programme exécutable