欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

ANSI - Unicode UTF16 - Unicode UTF8 轉(zhuǎn)換

系統(tǒng) 1905 0

ANSI - Unicode UTF16 - Unicode UTF8 轉(zhuǎn)換

又陷入了Unicode的泥潭,工作中遇到一個(gè)模塊需要從wchar_t* 轉(zhuǎn)到 char*,而且后續(xù)的工作都是基于Char*進(jìn)行的。網(wǎng)上找了下資料,代碼如下:

還有個(gè)搞人的東西是VS2005下的ifstream及ofstream函數(shù),打開(kāi)帶有中文路徑的文件會(huì)失敗。

解決方案非常HACK,例如

非簡(jiǎn)體中文操作系統(tǒng)如下解決:

std::locale prev_loc = std::locale::global( std::locale("chs") ); // 沒(méi)有這一句的話,文件打開(kāi)失敗
std::ifstream file( "d://測(cè)試//test.txt" );
std::locale::global( prev_loc ); // 沒(méi)有這一句的話,文件中的中文無(wú)法輸出,且wcout輸出中文也失敗

簡(jiǎn)體中文操作系統(tǒng)下,

std::locale::global( std::locale("") ); // 沒(méi)有這一句的話,文件打開(kāi)失敗
std::ifstream file( "d://測(cè)試//test.txt" );

--------------------------------------------------------------------------------------------------

#include <stdio.h>
#include <windows.h>
#include <locale.h>
#define BUFF_SIZE 1024

wchar_t * ANSIToUnicode( const char* str )
{
int textlen ;
wchar_t * result;
textlen = MultiByteToWideChar( CP_ACP, 0, str,-1, NULL,0 );
result = (wchar_t *)malloc((textlen+1)*sizeof(wchar_t));
memset(result,0,(textlen+1)*sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, 0,str,-1,(LPWSTR)result,textlen );
return result;
}

char * UnicodeToANSI( const wchar_t* str )
{
char* result;
int textlen;
textlen = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
result =(char *)malloc((textlen+1)*sizeof(char));
memset( result, 0, sizeof(char) * ( textlen + 1 ) );
WideCharToMultiByte( CP_ACP, 0, str, -1, result, textlen, NULL, NULL );
return result;
}

wchar_t * UTF8ToUnicode( const char* str )
{
int textlen ;
wchar_t * result;
textlen = MultiByteToWideChar( CP_UTF8, 0, str,-1, NULL,0 );
result = (wchar_t *)malloc((textlen+1)*sizeof(wchar_t));
memset(result,0,(textlen+1)*sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0,str,-1,(LPWSTR)result,textlen );
return result;
}

char * UnicodeToUTF8( const wchar_t* str )
{
char* result;
int textlen;
textlen = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
result =(char *)malloc((textlen+1)*sizeof(char));
memset(result, 0, sizeof(char) * ( textlen + 1 ) );
WideCharToMultiByte( CP_UTF8, 0, str, -1, result, textlen, NULL, NULL );
return result;
}
/*寬字符轉(zhuǎn)換為多字符Unicode - ANSI*/
char* w2m(const wchar_t* wcs)
{
int len;
char* buf;
len =wcstombs(NULL,wcs,0);
if (len == 0)
return NULL;
buf = (char *)malloc(sizeof(char)*(len+1));
memset(buf, 0, sizeof(char) *(len+1));
len =wcstombs(buf,wcs,len+1);
return buf;
}
/*多字符轉(zhuǎn)換為寬字符ANSI - Unicode*/
wchar_t* m2w(const char* mbs)
{
int len;
wchar_t* buf;
len =mbstowcs(NULL,mbs,0);
if (len == 0)
return NULL;
buf = (wchar_t *)malloc(sizeof(wchar_t)*(len+1));
memset(buf, 0, sizeof(wchar_t) *(len+1));
len =mbstowcs(buf,mbs,len+1);
return buf;
}

char* ANSIToUTF8(const char* str)
{
return UnicodeToUTF8(ANSIToUnicode(str));
}

char* UTF8ToANSI(const char* str)
{
return UnicodeToANSI(UTF8ToUnicode(str));
}

ANSI - Unicode UTF16 - Unicode UTF8 轉(zhuǎn)換


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 天天天天| 奇米影视首页 | 羞羞的小视频 | 日韩喷水| 久草在线资源福利站 | 成人做爰高潮片免费视频韩国 | 日本三级不卡 | 色综合网亚洲精品久久久 | 久久久精彩视频 | 日韩视频中文字幕 | 国产麻豆剧传媒精品好看的片 | 天天色天天操天天射 | 加勒比AV一本大道香蕉大在线 | 欧美激情啪啪 | 秋霞电影免费理论久久 | 久久88 | 日本高清视频www夜色资源网 | 成人免费影 | 婷婷激情综合色五月久久竹菊影视 | 久久久成 | 久久精品一 | 成人精品 | 亚洲精品国产第一区二区多人 | 99精品视频在线观看 | 国产91在线 | 欧美 | 二级黄| 日本无卡无吗在线 | 苏晓晖个人简介军衔 | 欧美9999 | 麻豆短视频传媒网站怎么找 | 插入综合网 | 精品一区二区三区的国产在线观看 | 成人免费毛片aaaaaa片 | a级在线观看 | 免费在线亚洲视频 | 亚洲天堂中文网 | 99精品在线观看 | 91青青国产在线观看免费 | 五月婷婷之综合激情 | 国产精品秒播无毒不卡 | 久久精品a一级国产免视看成人 |