- voidWStrToUTF8(std::string&dest,conststd::wstring&src){
- dest.clear();
-
- for(size_ti=0;i<src.size();i++){
- wchar_tw=src[i];
- if(w<=0x7f)
- dest.push_back((char)w);
- elseif(w<=0x7ff)
- {
- dest.push_back(0xc0|((w>>6)&0x1f));
- dest.push_back(0x80|(w&0x3f));
- }
- if(w<=0xffff)
- {
- dest.push_back(0xe0|((w>>12)&0x0f));
- dest.push_back(0x80|((w>>6)&0x3f));
- if(sizeof(wchar_t)>2&&w<=0x10ffff)
- dest.push_back(0xf0|((w>>18)&0x07));
- dest.push_back(0x80|((w>>12)&0x3f));
- dest.push_back(0x80|((w>>6)&0x3f));
- dest.push_back(0x80|(w&0x3f));
- }
- else
- dest.push_back('?');
-
-
- std::stringWStrToUTF8(conststd::wstring&str)
- std::stringresult;
- WStrToUTF8(result,str);
- returnresult;
- }
- 注意之前要添加类名哟。其他就跟源码是一样的了,希望对大家有所帮助,因为笔者当时就纠结于此。。。。。。
原文链接:https://www.f2er.com/cocos2dx/342608.html