科学计数法 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.

相关文章