cocos2d-x3.1.1 step by step 学习笔记2 cocos中的字符串
来源:互联网 发布:尸鳖特效软件 编辑:程序博客网 时间:2024/06/03 22:08
cocos2d-x中的字符串:
<1>:使用 const char* 和 std::string
const char* 是C风格的字符串 ,std::string 是C++风格的字符串,它封装了 const char *
初始化 std::string 对象:
std::string name = "tony";
std:: string name = std::string("Micheal");
std::string 指针类型:
std::string namep = new std::string("Micheal");
... ....
delete namep;
把std::string 类型转换为 const char* 类型:
const char* cstring = name.c_str();
const char* cstring = namep->c_str();
<2>:使用cocos2d::__string
来源于Objective-c 的NSString
创建它的主要的静态函数如下:
_static __String * create(const std::string &str)
_static__String* createWitnFormat(const char* format,......)
数据类型之间的转换:
cocos2d::__String 转为const char*类型 举例如下:
__String * name = __String::Create("Hi Micheal');
const char * cstring = name->getCstring();
const char* 转换为 cocos2d::__String类型,举例如下:
const char * cstring = "Hi Micheal";
__String* ns = __String::createWithFormat("%s",cstring);
std::string转换为cocos2d::__String()类型,举例如下:
std::string string = "Hi Micheal";
__String * ns = __String::CreateWithFormat("%s",string.c_str());
cocos2d::__String 转换为int类型
int num = 123;
__String * ns = __StringCretaeWitjFormat("%d",num);
int num2 = ns->intValue();
- cocos2d-x3.1.1 step by step 学习笔记2 cocos中的字符串
- cocos2d-x3.1.1 step by step 学习笔记1----- 软件的安装与HelloWord
- cocos2d-x3.1.1 step by step 学习笔记6 Sprite精灵类
- Spring Aop Step-By-Step 学习笔记
- Linux 学习 step by step (2)
- cocos2d-x 3.1.1 step by step 学习笔记3 Win32平台下中文乱码问题
- cocos2d-x 3.1.1 step by step 学习笔记4 标签使用
- cocos2d-x 3.1.1 step by step 学习笔记5 菜单使用
- cocos2d-x 3.1.1 step by step 学习笔记7 场景与层
- Vim学习 Step by Step
- C++学习--STEP BY STEP
- 汇编学习 step by step
- java 学习 step by step
- OpenCL 学习step by step
- gdb学习step by step
- android学习step by step.
- Spring Aop Step-By-Step 学习笔记(上)
- Spring Aop Step-By-Step 学习笔记(下)
- Search Insert Position
- C++中格式化cout输出
- hdu 3068 最长回文
- 03.抽象工厂模式--AbstractFactory
- SVN升级到1.8后 Upgrade working copy
- cocos2d-x3.1.1 step by step 学习笔记2 cocos中的字符串
- 泛型类型的转换,协变和逆变
- Spring配置连接池
- mini2440 简单的dma工作原理实验
- 不能使用ctrl+space切换中英文输入法的问题
- DXP如何对一类元件进行处理 例如在PCB中对一批元件进行修改层 将top layer 改为bottom layer
- ORACLE建立序列命令 SEQUENCE
- 已知树先序中序遍历,求后续 【java】
- 04.C++反射的实现