您的位置:首页 > 其它

int 转换成string 类型的方法

2011-02-23 20:32 363 查看
(1)使用ostringstream;

ostringstram oss;

oss << a;

string s = oss.str();

(2)使用sprintf

char buf[20] = {0};

sprintf(buf, "%d", a);

string s = buf;

(3)使用itoa

char buf[20] = {0};

string s = itoa(a, buf, 10);

(4)使用MFC的CString::Format:

CString s0;

s0.Format("%d", a);

(5)使用boost的lexical_cast:

string s = boost::lexical_cast<string>(a);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: