首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::hexfloat

Defined in header <ios>

?

?

std::ios_base& fixed( std::ios_base& str );

(1)

?

std::ios_base& scientific( std::ios_base& str );

(2)

?

std::ios_base& hexfloat( std::ios_base& str );

(3)

(since C++11)

std::ios_base& defaultfloat( std::ios_base& str );

(4)

(since C++11)

修改浮点输入/输出的默认格式。

1%29设置floatfield溪流strfixed好像通过打电话str.setf(std::ios_base::fixed,std::ios_base::floatfield)

2%29设置floatfield溪流strscientific好像通过打电话str.setf(std::ios_base::scientific,std::ios_base::floatfield)

3%29设置floatfield溪流strfixedscientific同时,好像通过呼叫str.setf(std::ios_base::fixed|std::ios_base::scientific,std::ios_base::floatfield)这将启用十六进制浮点格式设置。

4%29设置floatfield溪流str为零,仿佛通过调用str.unsetf(std::ios_base::floatfield)这将启用默认浮点格式,这与固定的和科学的格式不同.

这是一个I/O操作程序,可以用表达式调用它,如out << std::fixed对任何out类型std::basic_ostream或使用表达式,如in >> std::scientific对任何in类型std::basic_istream...

参数

str

-

reference to I/O stream

返回值

str%28操作后对流的引用%29。

注记

十六进制浮点格式会忽略流精度规范,这是std::num_put::do_put...

二次

代码语言:javascript
复制
#include <iostream>
#include <sstream>
 
int main()
{
    std::cout << "The number 0.01 in fixed:      " << std::fixed << 0.01 << '\n'
              << "The number 0.01 in scientific: " << std::scientific << 0.01 << '\n'
              << "The number 0.01 in hexfloat:   " << std::hexfloat << 0.01 << '\n'
              << "The number 0.01 in default:    " << std::defaultfloat << 0.01 << '\n';
    double f;
    std::istringstream("0x1P-1022") >> std::hexfloat >> f;
    std::cout << "Parsing 0x1P-1022 as hex gives " << f << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
The number 0.01 in fixed:      0.010000
The number 0.01 in scientific: 1.000000e-02
The number 0.01 in hexfloat:   0x1.47ae147ae147bp-7
The number 0.01 in default:    0.01
Parsing 0x1P-1022 as hex gives 2.22507e-308

二次

另见

setprecision

changes floating-point precision (function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com