包含:
#include <iostream>
#include <string>
#include <sstream>double转string
string DoubleToString(double Input)
{
stringstream Oss;
Oss<<Input;
return Oss.str();
}string转double
double StringToDouble(string Input)
{
double Result;
stringstream Oss;
Oss<<Input;
Oss>>Result;
return Result;
}
int main()
{
double Str_1 = 12345.56789;
string Str_2 = "12345.56789";
cout<<"Double --> String"<<endl;
cout<<DoubleToString(Str_1)<<endl;
cout<<"String --> Double"<<endl;
cout<<StringToDouble(Str_2)<<endl;
system("pause");
}效果图:
本文展示如何在C++中将双精度浮点数转换为字符串,以及如何从字符串中解析出双精度浮点数。通过提供具体的函数实现和实例演示,读者可以轻松掌握这一基本的数值类型转换技巧。
1347

被折叠的 条评论
为什么被折叠?



