cocos2d int, float, double, const char* 转string

来源:互联网 发布:js开头的白色车牌 编辑:程序博客网 时间:2024/05/16 17:36

(1)int, float, double 转 string


int i = 100;


std::string str = StringUtils::format("%d", i);


float f = 100.1f;


std::string str2 = StringUtils::format("%f", f);


double d = 100.2;


std::string str2 = StringUtils::format("%d", d);


(2)const char* 转 string


const char* 可以直接复制给string


(3)组合拼接


int i = 1;

std::string str = StringUtils::format("people%d.png", i);


std::string str2 = StringUtils::format(%s%d.png", "people", i);

0 0
原创粉丝点击