用stringstream实现从数字到字符串的转化

代码简单,字符串到数字和数字到字符串的写法类似。

#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;
}

——

猜你喜欢

转载自www.cnblogs.com/cunyusup/p/8945951.html