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);
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);
相关文章推荐
- C# 0、1 状态转换(int 类型转string 类型的方法)
- JAVA中int、String的类型转换方法汇总及差异
- java中Object转换成int或String类型方法
- int、double、boolean、char、float、long、Object等七种数据类型转换成String数据类型 用到的方法是String.valueOf();
- int类型转换为string类型的两种方法
- java中Object转换成int或String类型方法
- Go语言string,int,int64 ,float之间类型转换方法
- 浅述int与string类型转换的两种方法
- java中将Object转换成 String类型和int类型的方法 和Object数组转换成String数组的方法
- int类型和String类型相互转换方法总结
- 1 String转换为int类型的方法
- 转载关于int与string类型转换的两种方法
- 关于C++中string对象向int、float、double类型的转换的方法汇总
- C++中int类型转换成string类型的方法
- java判断String类型是否能转换为int的方法
- java中int类型转换成String类型的三种方法
- Android String类型转换为float、double和int的工具类方法
- Swift 如何将数字型字符串转换成String类型 (toInt()方法) 及返回值未解包的原因
- Go语言string,int,int64 ,float之间类型转换方法
- java中int和string类型之间转换的几种方法