命名空间
变体
操作

std::showbase, std::noshowbase

来自 cppreference.cn
< cpp‎ | io‎ | manip
 
 
 
输入/输出操纵器
浮点格式化
整数格式化
showbasenoshowbase
布尔格式化
字段宽度和填充控制
其他格式化
空白字符处理
输出刷新
(C++20)  

状态标志操作
时间与金钱 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 中的 showbase 标志,如同调用了 str.setf(std::ios_base::showbase)
2) 禁用流 str 中的 showbase 标志,如同调用了 str.unsetf(std::ios_base::showbase)

这是一个 I/O 操作器,可以与形如 out << std::showbase 的表达式一同调用,其中 out 的类型为 std::basic_ostream,或者与形如 in >> std::showbase 的表达式一同调用,其中 in 的类型为 std::basic_istream

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 affects the output of octals and hexadecimals
    std::cout << std::hex
              << "showbase: " << std::showbase << 42 << '\n'
              << "noshowbase: " << std::noshowbase << 42 << '\n';
 
    // and both input and output of monetary values
    std::locale::global(std::locale("en_US.UTF8"));
    long double val = 0;
    std::istringstream("3.14") >> std::showbase >> std::get_money(val);
    std::cout << "With showbase, parsing 3.14 as money gives " << val << '\n';
    std::istringstream("3.14") >> std::noshowbase >> std::get_money(val);
    std::cout << "Without showbase, parsing 3.14 as money gives " << val << '\n';
}

输出

showbase: 0x2a
noshowbase: 2a
With showbase, parsing 3.14 as money gives 0
Without showbase, parsing 3.14 as money gives 314

[编辑] 参阅

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