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は8進数と16進数の出力に影響する
    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 << "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
With showbase, parsing 3.14 as money gives 0
Without showbase, parsing 3.14 as money gives 314

関連項目

指定された ios_base フラグをクリア
(関数)
指定された ios_base フラグを設定
(関数)