std::showbase, std::noshowbase
來自 cppreference.com
定義於標頭檔案 <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 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 標誌(函式) |