标准的c++中int,float,double等怎么转换成string类
3 回答
手掌心
TA贡献1942条经验 获得超3个赞
c++的标准作法是通过stringstream。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <iostream> #include <sstream> #include <string>
using namespace std;
int main(int argc, char const *argv[]) { stringstream ss; string str; int i = 1; float f = 10.1; double d = 100.11;
ss << i << "," << f << "," << d << endl; ss >> str; cout << str;
return 0; } |
运行:
1 | 1,10.1,100.11 |
- 3 回答
- 0 关注
- 1621 浏览
添加回答
举报
0/150
提交
取消