代码简单,字符串到数字和数字到字符串的写法类似。
#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; }
——