函式
<ios> <iostream>

std::showbase

ios_base& showbase (ios_base& str);
顯示數字的進位制字首
str 流設定 showbase 格式標誌。

當設定 showbase 格式標誌時,插入輸出流的數值整型將帶有 C++ 字面量常量使用的相同字首:十六進位制值帶有 0x (參見 hex),八進位制值帶有 0 (參見 oct),而十進位制值則沒有字首 (參見 dec)。

可以使用 noshowbase 操縱器來取消設定此選項。當未設定時,所有數值都將不帶進位制字首插入。

對於標準流,showbase 標誌在初始化時是未設定的。

引數

str
格式標誌受影響的流物件。
因為此函式是一個操縱符,它被設計為在不帶引數的情況下,與流上的插入 (<<) 和提取 (>>) 操作結合使用(見下例)。

返回值

引數 str

示例

1
2
3
4
5
6
7
8
9
// modify showbase flag
#include <iostream>     // std::cout, std::showbase, std::noshowbase

int main () {
  int n = 20;
  std::cout << std::hex << std::showbase << n << '\n';
  std::cout << std::hex << std::noshowbase << n << '\n';
  return 0;
}

輸出
0x14
14


資料競爭

修改 str。對同一個流物件的併發訪問可能導致資料競爭。

異常安全

基本保證:如果丟擲異常,str 處於有效狀態。

另見