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