名稱空間
變體
操作

std::showbase, std::noshowbase

來自 cppreference.com
< cpp‎ | io‎ | manip
 
 
 
輸入/輸出操縱器
浮點格式化
整數格式化
showbasenoshowbase
布林格式化
欄位寬度和填充控制
其他格式化
空白字元處理
輸出重新整理
(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) 啟用流 str 中的 showbase 標誌,如同呼叫了 str.setf(std::ios_base::showbase)
2) 停用流 str 中的 showbase 標誌,如同呼叫了 str.unsetf(std::ios_base::showbase)

這是一個 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 標誌
(函式) [編輯]