在做数据转换时,最好包含以下头文件
- #include <iostream>
- #include<cmath>
- <string>
- <sstream>
- USING_NS_CC;
- using namespacestd;
string s(char *);
inta=3;
CCString* ns=CCString::createWithFormat("%d",a);
strings=ns->m_sString;
======================================
string
std::string str = "123";
CCString* ns=CCString::createWithFormat("%s",str.c_str());
CCString
std::strings= ns->m_sString;//ns是一个CCString*类型
======================================
char 转
int 转 char
inta=3;
CCString* ns=CCString::createWithFormat("%d",a);
constchar* s=ns->getCString();
这里额外提一下,IOS在参与跨平台用到的编码格式转换
格式刷:
转换编码格式为utf-8
NSString
const char *char_gurl = [endstr cStringUsingEncoding:NSUTF8StringEncoding];
const char* gameObject;
NSString *char_gameObject = [[NSString alloc] initWithCString:(const char*)gameObject
char* 转 URL
const char* url;
NSString *char_url = [[NSString alloc] initWithCString:(const char*)url
NSURL* url=[NSURL URLWithString:char_url];
//NSString转char * /const char *
NSString* strPath = [NSStringstringWithUTF8String:filename];
constchar* filePathChar = [filePathUTF8String];