读写使用std :: hexfloat [英] Read and write using std::hexfloat
本文介绍了读写使用std :: hexfloat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这段代码在我的机器上打印了 0
,但我期望 0.3
。怎么了?我在最新的Arch Linux上使用g ++ 6.3.1。编译标志看起来不新鲜。
#include< iostream>
#include< sstream>
int main(){
std :: stringstream s;
s<< std :: hexfloat<< 0.3 <的std :: ENDL;
double d = -1.0;
while(s>> std :: hexfloat>> d)
std :: cout<< d<的std :: ENDL;
解决方案使用
double d = std :: strtod(s.str()。c_str(),NULL);
作为解决方法。这似乎是一个错误。 This piece of code printed 0
on my machine, but I expected 0.3
. What's wrong? I'm using g++ 6.3.1 on latest Arch Linux. Compilation flags seem unrelevent.
#include <iostream>
#include <sstream>
int main() {
std::stringstream s;
s << std::hexfloat << 0.3 << std::endl;
double d = -1.0;
while(s >> std::hexfloat >> d)
std::cout << d << std::endl;
}
解决方案
Use double d = std::strtod(s.str().c_str(), NULL);
as a workaround. It seems like a bug.
这篇关于读写使用std :: hexfloat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文