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

std::hex

Defined in header <ios>

?

?

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

(1)

?

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

(2)

?

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

(3)

?

修改整数I/O的默认数字基。

1%29设置basefield溪流strdec好像通过打电话str.setf(std::ios_base::dec,std::ios_base::basefield)...

2%29设置basefield溪流strhex好像通过打电话str.setf(std::ios_base::hex,std::ios_base::basefield)...

3%29设置basefield溪流stroct好像通过打电话str.setf(std::ios_base::oct,std::ios_base::basefield)...

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

参数

str

-

reference to I/O stream

返回值

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

二次

代码语言:javascript
复制
#include <iostream>
#include <sstream>
int main()
{
    std::cout << "The number 42 in octal:   " << std::oct << 42 << '\n'
              << "The number 42 in decimal: " << std::dec << 42 << '\n'
              << "The number 42 in hex:     " << std::hex << 42 << '\n';
    int n;
    std::istringstream("2A") >> std::hex >> n;
    std::cout << std::dec << "Parsing \"2A\" as hex gives " << n << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
The number 42 in octal:   52
The number 42 in decimal: 42
The number 42 in hex:     2a
Parsing "2A" as hex gives 42

二次

另见

setbase

changes the base used for integer I/O (function)

showbasenoshowbase

controls whether prefix is used to indicate numeric base (function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com