String in scientific notation C++ to double conversion(科学计数法 C++ 中的字符串到双重转换)
问题描述
我有一个数据库,里面装满了像下面这样的双精度数:
I've got a database filled up with doubles like the following one:
1.60000000000000000000000000000000000e+01
有人知道如何在 C++ 中将这样的数字转换为双精度数吗?
Does anybody know how to convert a number like that to a double in C++?
有没有一种标准"的方式来做这类事情?还是我必须推出自己的功能?
Is there a "standard" way to do this type of things? Or do I have to roll my own function?
现在我正在做这样的事情:
Right now I'm doing sth like this:
#include <string>
#include <sstream>
int main() {
std::string s("1.60000000000000000000000000000000000e+01");
std::istringstream iss(s);
double d;
iss >> d;
d += 10.303030;
std::cout << d << std::endl;
}
谢谢!
推荐答案
像这样?这将是C++"的做法......
Something like this? This would be the "C++" way of doing it...
#include <sstream>
using namespace std;
// ...
string s = "1.60000000000000000000000000000000000e+01";
istringstream os(s);
double d;
os >> d;
cout << d << endl;
打印 16.
这篇关于科学计数法 C++ 中的字符串到双重转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:科学计数法 C++ 中的字符串到双重转换


基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 我有静态或动态 boost 库吗? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01