命名空间
变体
操作

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,对于任何 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 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 标志
(函数) [编辑]