名前空間
変種
操作

std::showbase, std::noshowbase

From cppreference.com
< cpp‎ | io‎ | manip
 
 
 
入出力マニピュレータ
浮動小数点フォーマット
整数フォーマット
showbasenoshowbase
boolフォーマット
フィールド幅と埋め文字制御
その他のフォーマット
空白文字の処理
出力のフラッシュ
(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) ストリーム strshowbase フラグを有効にします。これは str.setf(std::ios_base::showbase) を呼び出すのと同じです。
2) ストリーム strshowbase フラグを無効にします。これは str.unsetf(std::ios_base::showbase) を呼び出すのと同じです。

これは I/O マニピュレータです。 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 - 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フラグを設定する
(関数) [編集]
English 日本語 中文(简体) 中文(繁體)