在线文档教程
C++
输入/输出 | Input/output

std::oct

STD:DEC,STD::十六进制,STD::OCT

Defined in header
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。

二次

#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'; }

二次

产出:

二次

The number 42 in octal: 52 The number 42 in decimal: 42 The number 42 in hex: 2a Parsing "2A" as hex gives 42

二次

另见

setbasechanges the base used for integer I/O (function)
showbasenoshowbasecontrols whether prefix is used to indicate numeric base (function)

© cppreference.com

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

http://en.cppreference.com/w/cpp/io/manip/hex