<版本:cocos2D-x——V2.2.1>
主角:libiconv.lib
Cocos2D-x内部是以UTF8编码方式处理文本的;
VS默认的字符编码是GBK2312,添加'L'为UNICODE编码
是故,cocos2d中不能直接使用之
解决办法有三:
一、将源代码文件保存为UTF8编码文件,但是这种方式认编译器,不可取
二、将字符串用UTF8编码保存到一个文件中,然后用代码读取这些字符串使用,下面介绍我老大给的方法
相关资源下载地址:http://download.csdn.net/detail/u012898195/6844305
附上代码(其中CSVParse.h在上述地址中下载):
#include "HelloWorldScene.h"
#include "CSVParse.h"
#include <map>
USING_NS_CC;
using namespace std;
bool HelloWorld::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(! CCLayer::init());
CCSize size = CCDirector::sharedDirector()->getWinSize();
// 解析字符串文件
map<string,string> mapStr; // 字符串映射
CSVParse* par = new CSVParse;
par->initWidthFile("data/string.csv");
par->Before();
while(par->Next())
{
string key = par->Read("key");
string wenzi = par->Read("wenzi");
mapStr[key] = wenzi;
}
delete par; // end
// 使用解析结果 mapStr
CCLabelTTF* label = CCLabelTTF::creat