std::dec, std::hex, std::oct
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <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) 原文:
Modifies the default numeric base for integer I/O
设置
2) basefield
的流str
dec
仿佛通过调用str.setf(std::ios_base::dec, std::ios_base::basefield)原文:
sets the
basefield
of the stream str
to dec
as if by calling str.setf(std::ios_base::dec, std::ios_base::basefield)设置
3) basefield
的流str
hex
仿佛通过调用str.setf(std::ios_base::hex, std::ios_base::basefield)原文:
sets the
basefield
of the stream str
to hex
as if by calling str.setf(std::ios_base::hex, std::ios_base::basefield)设置
basefield
的流str
oct
仿佛通过调用str.setf(std::ios_base::oct, std::ios_base::basefield)原文:
sets the
basefield
of the stream str
to oct
as if by calling 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.原文:
This is an I/O manipulator, it may be called with an expression such as out << std::hex for any
out
of type std::basic_ostream or with an expression such as in >> std::hex for any in
of type std::basic_istream.目录 |
[编辑] 参数
str | - | 参考I / O流
|
[编辑] 返回值
str
(参考操作后到流)原文:
str
(reference to the stream after manipulation)[编辑] 示例
#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
[编辑] 另请参阅
改变用于整数I / O基地 原文: changes the base used for integer I/O (函数) | |
控制是否前缀用于指示数字基 原文: controls whether prefix is used to indicate numeric base (函数) |