cocos2dx20升级到cocos2dx 317后unsigned short wtext = wcharFromStringtextc_str &stringLen; 中的wcharFromString没了如何使用cc_utf8_to_utf16替换
在Cocos2d-x 3.17版本中,cc_utf8_to_utf16函数可以用来替换wcharFromString函数。
cc_utf8_to_utf16函数的定义如下:
unsigned short* cc_utf8_to_utf16(const char* str_old, int length, int* rUtf16Size)
你可以按照以下方式使用cc_utf8_to_utf16函数替换wcharFromString函数:
std::string text = "你好";
int stringLen = 0;
unsigned short* wtext = cc_utf8_to_utf16(text.c_str(), -1, &stringLen);
这样就可以将UTF-8编码的字符串转换为UTF-16编码的unsigned short数组了。
原文地址: https://www.cveoy.top/t/topic/hYBG 著作权归作者所有。请勿转载和采集!