cocos2d-x 打印中文、显示中文

BOOL WCharToMByte(LPCWSTR lpcwszStr, LPSTR lpszStr, DWORD dwSize)
{
DWORD dwMinSize;
dwMinSize = WideCharToMultiByte(CP_UTF8,NULL,lpcwszStr,-1,NULL,0,NULL,FALSE);
if(dwSize < dwMinSize)
{
return FALSE;
}
WideCharToMultiByte(CP_UTF8,NULL,lpcwszStr,-1,lpszStr,dwSize,NULL,FALSE);
return TRUE;

}


wchar_t wText[10] = {L"输出中文"};
char sText[20]= {0};
WCharToMByte(wText,sText,sizeof(sText)/sizeof(sText[0]));


CCLabelTTF* pLabel = CCLabelTTF::create(sText, "宋体", 24);

CCSize size = CCDirector::sharedDirector()->getWinSize();

pLabel->setPosition( ccp(size.width / 2, size.height - 150) );


// add the label as a child to this layer
this->addChild(pLabel, 1);


CCLog( "sText: %s",sText );


你可能感兴趣的:(cocos2d-x 打印中文、显示中文)