描述
它用於設置 str 流的 showbase 格式標誌。設置 showbase 格式標誌後,插入到輸出流中的數字整數值的前綴與 C++ 文字常量使用的前綴相同:0x 表示十六進製值(參見 hex),0 表示八進製值(參見 oct),decimal-base 值沒有前綴(見十二月)。
聲明
以下是 std::showbase 函數的聲明。
ios_base& showbase (ios_base& str);
參數
str− 格式標誌受到影響的流對象。
返回值
它返回參數 str。
異常
Basic guarantee- 如果拋出異常,則 str 處於有效狀態。
數據競爭
它修改了 str。對同一個流對象的並發訪問可能會導致數據競爭。
示例
在下麵的示例中解釋了 std::showbase 函數。
#include <iostream>
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
相關用法
- C++ ios showpos用法及代碼示例
- C++ ios showpoint用法及代碼示例
- C++ ios setstate()用法及代碼示例
- C++ ios skipws用法及代碼示例
- C++ ios eof()用法及代碼示例
- C++ ios manipulators boolalpha()用法及代碼示例
- C++ ios Scientific用法及代碼示例
- C++ ios manipulators left()用法及代碼示例
- C++ ios fixed用法及代碼示例
- C++ ios manipulators dec()用法及代碼示例
- C++ ios manipulators uppercase()用法及代碼示例
- C++ ios noshowbase用法及代碼示例
- C++ ios manipulators hex()用法及代碼示例
- C++ ios manipulators unitbuf()用法及代碼示例
- C++ ios manipulators nouppercase()用法及代碼示例
- C++ ios manipulators skipws()用法及代碼示例
- C++ ios dec用法及代碼示例
- C++ ios Internal用法及代碼示例
- C++ ios manipulators internal()用法及代碼示例
- C++ ios hex用法及代碼示例
注:本文由純淨天空篩選整理自 C++ ios Library - Showbase Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。