int 转换成string 类型的方法

来源:互联网 发布:java多线程wait sleep 编辑:程序博客网 时间:2024/06/02 17:45

(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);