名前空間
変種
操作

std::showbase, std::noshowbase

提供: cppreference.com
< cpp‎ | io‎ | manip
 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
入出力マニピュレータ
浮動小数点フォーマット
整数フォーマット
showbasenoshowbase
ブーリアンフォーマット
フィールド幅とフィル制御
その他のフォーマット
ホワイトスペース処理
出力のフラッシュ
ステータスフラグ操作
時間と通貨の入出力
(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) を呼んだかのように、ストリーム strshowbase フラグを有効化します。

2) str.unsetf(std::ios_base::showbase) を呼んだかのように、ストリーム strshowbase フラグを無効化します。

これは入出力マニピュレータであるため、 std::basic_ostream 型の任意の out に対する out << std::showbase のような式や std::basic_istream 型の任意の in に対する in >> std::showbase のような式で呼ぶことができます。

showbase フラグは整数の出力 (std::num_put::put を参照)、金額の入力 (std::money_get::get を参照) および金額の出力 (std::money_put::put を参照) の動作に影響を与えます。

目次

[編集] 引数

str - 入出力ストリームへの参照

[編集] 戻り値

str (操作後のストリームへの参照)。

[編集] ノート

std::num_put::put で規定されているように、整数の出力における showbase フラグは std::printf の # 書式指定子のように振る舞います。 つまり、値ゼロを出力するときは基数の接頭辞を追加しないという意味です。

[編集]

#include <sstream>
#include <locale>
#include <iostream>
#include <iomanip>
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 is("3.14");
    is >> std::showbase >> std::get_money(val);
    std::cout << "With showbase, parsing 3.14 as money gives " << val << '\n';
    is.seekg(0);
    is >> 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 のフラグをクリアします
(関数) [edit]
指定された ios_base のフラグを設定します
(関数) [edit]