字符串转double,double转字符串各种操作

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;

int main()
{
    /*
    stringstream ss;
    string a = "10.919";
    ss << a;
    double b ;
    ss >> b;
    cout << b <<endl;
    */
    /*
    string s = "10.999";
    double a = stod(s);//stoi stof
    cout << a <<endl;
    */
//    double d = 9.9919;
//    cout  << fixed << setprecision(2) << d <<endl;//#include <iomanip>
//    string s = to_string(d);
//    cout << s <<endl;
     double d1 = 9.88;
     stringstream ss;
     ss << d1;
     string str;
     ss >> str;
     cout << str <<endl;
     return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_34068766/article/details/82464216