首页 > 代码库 > C++中string类型对象和double型变量之间的互相转换

C++中string类型对象和double型变量之间的互相转换

//convert string type value to double type value
string s = "23";
double d;
istringstream is(s);
is>>d;
cout<<d<<endl;   //输出23

 

//convert double type value to string type value
double d=45;
string s;
ostringstream os;
os<<d;
s = os.str();
cout<<s<<endl;  //输出45