How to CCLabelTTF::setString unicode characters

std::string utf8_encode(const std::wstring &wstr)
{
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
std::string strTo( size_needed, 0 );
WideCharToMultiByte (CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
return strTo;
}
std::wstring ws(L“我6我”);
std::string str=utf8_encode(ws);
CCLabelTTF* label = CCLabelTTF::labelWithString(str.c_str(), “Arial”, 24);

WideCharToMultiByte is win32 function.

so can’t compile in android gcc enviroment.

then how to convert UTF-8 character string? or,

is cocos2d-x support to unicode TCHAR wchar_t etc…?

thanks.

cocos2d-x only supports UTF-8.
I’d suggest you record strings in a file which is UTF-8 format.

As far as I understand it, is UTF-8 able to be used with unicode (see an example). Can I use cocos2d-x today to use a emoji such as :sweat_smile:? The main problem is std::string, which doesn’t support it.

UTF-8 is compressed unicode. Cocos and std::string both support UTF-8.

Cocos functions to convert unicode to/from UTF-8 are in ccUTF8.h

But I still can’t show :sweat_smile: within a label. Can you show me a snipped, how to do it?

Cocos has test for unicode strings.

Run cpp-tests.
Go to 30: Node: Label - New API
Go to 9: New Label + Bitmap font