標準的c++中int,float,double等怎么轉換成string類
3 回答
千萬里不及你
TA貢獻1784條經驗 獲得超9個贊
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 關注
- 451 瀏覽
添加回答
舉報
0/150
提交
取消
