1. 程式人生 > >用stringstream實現從數字到字符串的轉化

用stringstream實現從數字到字符串的轉化

ring 寫法 IT namespace out pac AI color end

代碼簡單,字符串到數字和數字到字符串的寫法類似。

#include <sstream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    double num = 0.123456;
    string s;
    stringstream sstream;

    sstream << num;
    sstream >> s;

    cout << s << endl;

    sstream.clear();

    return
0; }

——

用stringstream實現從數字到字符串的轉化