Click here to Skip to main content
15,906,097 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
int _tmain(int argc, _TCHAR* argv[])
{
int mMinSize;
string mstrReturn;
char *mcharReturn;
const WCHAR *mchar;

///*******************************OK*************************************
wstring mstr01 = _T("钓鱼岛是中国的");
mchar = mstr01.c_str();
mMinSize = WideCharToMultiByte(CP_ACP, NULL, mchar, -1, NULL, 0, NULL, FALSE);
mcharReturn = new char[mMinSize];
WideCharToMultiByte(CP_ACP, NULL, mchar, -1, mcharReturn, mMinSize, NULL, FALSE);
//mcharReturn = "钓鱼岛是中国的"

///*******************************OK*************************************
wstring mstr02 = _T("釣魚台は中国の");
mchar = mstr02.c_str();
mMinSize = WideCharToMultiByte(CP_ACP, NULL, mchar, -1, NULL, 0, NULL, FALSE);
mcharReturn = new char[mMinSize];
WideCharToMultiByte(CP_ACP, NULL, mchar, -1, mcharReturn, mMinSize, NULL, FALSE);
//mcharReturn = "釣魚台は中国の"

///*******************************NG*************************************
wstring mstr03 = _T("한국어");
mchar = mstr03.c_str();
mMinSize = WideCharToMultiByte(CP_ACP, NULL, mchar, -1, NULL, 0, NULL, FALSE);
mcharReturn = new char[mMinSize];
WideCharToMultiByte(CP_ACP, NULL, mchar, -1, mcharReturn, mMinSize, NULL, FALSE);
//mcharReturn = "???"

///*******************************NG*************************************
wstring mstr04 = _T("دياو هو الصين");
mchar = mstr04.c_str();
mMinSize = WideCharToMultiByte(CP_ACP, NULL, mchar, -1, NULL, 0, NULL, FALSE);
mcharReturn = new char[mMinSize];
WideCharToMultiByte(CP_ACP, NULL, mchar, -1, mcharReturn, mMinSize, NULL, FALSE);
//mcharReturn = "???? ?? ?????"

///*******************************OK*************************************
wstring mstr05 = _T("Diaoyutai Китая");
mchar = mstr05.c_str();
mMinSize = WideCharToMultiByte(CP_ACP, NULL, mchar, -1, NULL, 0, NULL, FALSE);
mcharReturn = new char[mMinSize];
WideCharToMultiByte(CP_ACP, NULL, mchar, -1, mcharReturn, mMinSize, NULL, FALSE);
//mcharReturn = "Diaoyutai Китая"


return 0;
}
Posted
Comments
chandanadhikari 15-Apr-15 9:06am    
can you please try using "CP_UTF8" in place of "CP_ACP" where ever it does not work. making a guess here but it might work !!
Reason Jiang 15-Apr-15 9:47am    
no,not solve the problem!

1 solution

Multi byte (ANSI) strings can represent only a specific set of characters according to the selected code page. When trying to convert a wide string, the characters that aren't covered by the code page are replaced with a replacement character which is '?' for most code pages.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900