std::showbase, std::noshowbase
From cppreference.com
| ヘッダ <ios>で定義 |
||
| std::ios_base& showbase( std::ios_base& str ); |
(1) | |
| std::ios_base& noshowbase( std::ios_base& str ); |
(2) | |
これは 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フラグを設定する(関数) |