标签:
在做数据转换时,最好包含以下头文件
//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互转)
标签:
原文地址:http://www.cnblogs.com/damowang/p/4329967.html