1、char*转string
char*cp="char"; std::stringsp=cp;
2、string转char*
//1 std::stringstr="string"; constchar*cp=str.data(); //2 std::stringstr="string"; constchar*cp=str.c_str(); //3 std::stringstr="hello"; charp[10]; str.copy(p,4,1);//这里4,代表复制几个字符,1代表复制的开始位置index *(p+4)='\0';//要手动加上结束符
3、int转string
intnumber=32; chartemp[10]; sprintf(temp,"%d",number,10); std::strings=temp;
4、Cocos2d专有的转换方法
intindex=100; std::stringstr=Value(index).asstring(); intindex2=Value(str).asInt();
原文地址:https://www.jb51.cc/cocos2dx/345085.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。