cocos2d-x类型转换(CCstring int string char UTF-8互转)
Posted N4
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cocos2d-x类型转换(CCstring int string char UTF-8互转)相关的知识,希望对你有一定的参考价值。
http://www.cnblogs.com/leehongee/p/3642308.html
//int 转 CCstring int num=5; CCString* ns=CCString::createWithFormat("%d",num); //CCstring 转 int int px = ns->intValue();//将CCString 转换为int的方法,转成float类型有 floatValue() //====================================== //CCString 转 char const char *string= ns->getCString(); //char 转 CCString CString.Format(”%s”,char *)//char 转cstring CCString* ns=CCString::createWithFormat("%s",char *); //====================================== //string 转 char const char *string=std::string("STRING").c_str(); char 转 string string s(char *); //====================================== //string 转 int std::string s("1234"); int n = std::atoi(s.c_str());//函数原型int atoi(const char *); //int 转 string int a=3; CCString* ns=CCString::createWithFormat("%d",a); string s=ns->m_sString; //====================================== //string 转 CCString std::string str = "123"; CCString* ns=CCString::createWithFormat("%s",str.c_str()); CCString 转 string std::string s= ns->m_sString;//ns是一个CCString*类型 //====================================== //char 转 int char *buf = "1122"; int n = std::atoi(buf); //int 转 char int a=3; CCString* ns=CCString::createWithFormat("%d",a); const char* s=ns->getCString();
以上是关于cocos2d-x类型转换(CCstring int string char UTF-8互转)的主要内容,如果未能解决你的问题,请参考以下文章
Cocos2d-x Android环境中Lua脚本的io操作
create a cocos2d-x-3.0 project in Xcode
cocos2d-x学习笔记使用NDK自带的iconv进行编码转换
cocos2d-x-3.0beta2创建项目遇到“UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in pos