Namespaces
Variants

std:: showbase, std:: noshowbase

From cppreference.net
< cpp ‎ | io ‎ | manip
Input/output manipulators
Floating-point formatting
Integer formatting
showbase noshowbase
Boolean formatting
Field width and fill control
Other formatting
Whitespace processing
Output flushing
Status flags manipulation
Time and money I/O
(C++11)
(C++11)
(C++11)
(C++11)
Quoted manipulator
(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 影响八进制和十六进制的输出
    std::cout << std::hex
              << "showbase: " << std::showbase << 42 << '\n'
              << "noshowbase: " << std::noshowbase << 42 << '\n';
    // 同时影响货币值的输入和输出
    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 标志
(函数)