std::showbase, std::noshowbase

来自cppreference.com
< cpp‎ | io‎ | manip
 
 
 
输入/输出操纵符
浮点格式化
整数格式化
showbasenoshowbase
布尔格式化
域宽与填充控制
其他格式化
空白符处理
输出冲入
状态标志操纵
时间与金钱 I/O
(C++11)
(C++11)
(C++11)
(C++11)
带引号操纵符
(C++14)
 
在标头 <ios> 定义
std::ios_base& showbase(std::ios_base& str );
(1)
std::ios_base& noshowbase(std::ios_base& str );
(2)
1) 如同以调用 str.setf(std::ios_base::showbase) 启用流 str 中的 showbase 标志。
2) 如同以调用 str.unsetf(std::ios_base::showbase) 禁用流 str 中的 showbase 标志。

这是 I/O 操纵符,可用如 out << std::showbase 的表达式对任何 std::basic_ostream 类型 out 的,或用如 in >> std::showbase 的表达式对任何 std::basic_istream 类型的 in 调用。

showbase 标志影响整数输出(见 std::num_put::put)、货币输入(见 std::money_get::get)和货币输出(见 std::money_put::put)的行为。

目录

[编辑]参数

str - 到 I/O 流的引用

[编辑]返回值

str(到操纵后的流的引用)。

[编辑]注解

std::num_put::put 中指定,整数输出中的 showbase 标志表现类似 std::printf 中的 # 格式指定符,这表示输出值为零时添加数值底前缀。

[编辑]示例

#include <iomanip>#include <iostream>#include <locale>#include <sstream>   int main(){// showbase 影响八进制和十六进制的输出std::cout<<std::hex<<"showbase: "<< std::showbase<<42<<'\n'<<"noshowbase: "<< std::noshowbase<<42<<'\n';   // 及货币值的输入和输出std::locale::global(std::locale("en_US.UTF8"));longdouble val =0;std::istringstream("3.14")>> std::showbase>>std::get_money(val);std::cout<<"用 showbase,解析 3.14 为货币得到 "<< val <<'\n';std::istringstream("3.14")>> std::noshowbase>>std::get_money(val);std::cout<<"不用 showbase,解析 3.14 为货币得到 "<< val <<'\n';}

输出:

showbase: 0x2a noshowbase: 2a 用 showbase,解析 3.14 为货币得到 0 不用 showbase,解析 3.14 为货币得到 314

[编辑]参阅

清除指定的 ios_base 标志
(函数)[编辑]
设置指定的 ios_base 标志
(函数)[编辑]
close