在C ++中以'D'作为指数前缀读取双重科学符号 [英] Read double scientific notation with 'D' as exponent prefix in C++
问题描述
我正在尝试读取写为-0.49430978D-02
的值,但它们仅以-0.49430978
的形式出现.我将字符保存在字符串vs
中,并且都尝试过
myval = stod(vs)
以及
sscanf(vs.c_str(), "%le", &myval)
但是他们两个都没有读懂科学计数法中的指数.是因为它是D
而不是E
吗?如何在c++
中正确读取此值?
D
格式是某些Fortran实现常见的不常见浮点表示形式,用于表示双精度(或更高精度). AFAIK,所有其他环境都将E
用作浮点,并且不表示底层精度.
我认为您唯一的选择是将值读取为字符串,用E
替换任何D
字符,然后用strtod()
或同等功能完成处理.
I am trying to read values that are written as -0.49430978D-02
, but they are only coming in as -0.49430978
. I have the characters saved in a string vs
and have attempted both
myval = stod(vs)
as well as
sscanf(vs.c_str(), "%le", &myval)
but both of them fail to read the exponent in the scientific notation. Is it because it is D
and not E
? How do I read this value correctly in c++
?
The D
format is an uncommon floating point representation common to some Fortran implementations to indicate double precision (or greater). AFAIK, all other environments use E
for floating point and do not indicate the underlying precision.
I think your only choice is to read the value as a string, replace any D
characters with E
and then finish processing with strtod()
or equivalent.
这篇关于在C ++中以'D'作为指数前缀读取双重科学符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!