std::ios_base::fmtflags
來自 cppreference.com
typedef /*implementation defined*/ fmtflags; |
||
static constexpr fmtflags dec = /*implementation defined*/ static constexpr fmtflags oct = /*implementation defined*/ |
||
static constexpr fmtflags left = /*implementation defined*/ static constexpr fmtflags right = /*implementation defined*/ |
||
static constexpr fmtflags scientific = /*implementation defined*/ static constexpr fmtflags fixed = /*implementation defined*/ |
||
static constexpr fmtflags boolalpha = /*implementation defined*/ static constexpr fmtflags showbase = /*implementation defined*/ |
||
指定可用的格式化標誌。它是一個 BitmaskType。定義了以下常量:
常量 | 解釋 |
dec | 對整數 I/O 使用十進位制基數:參閱 std::dec |
oct | 對整數 I/O 使用八進位制基數:參閱 std::oct |
hex | 對整數 I/O 使用十六進位制基數:參閱 std::hex |
basefield | dec | oct | hex。對掩碼操作有用。 |
left | 左對齊(在右側新增填充字元):參閱 std::left |
right | 右對齊(在左側新增填充字元):參閱 std::right |
internal | 內部對齊(在內部指定點新增填充字元):參閱 std::internal |
adjustfield | left | right | internal。對掩碼操作有用。 |
scientific | 使用科學計數法生成浮點型別,如果與 fixed 結合,則使用十六進位制計數法:參見 std::scientific |
fixed | 使用固定計數法生成浮點型別,如果與 scientific 結合,則使用十六進位制計數法:參見 std::fixed |
floatfield | scientific | fixed。對掩碼操作有用。 |
boolalpha | 以字母數字格式插入和提取 bool 型別:參閱 std::boolalpha |
showbase | 為整數輸出生成指示數字基數的字尾,在貨幣 I/O 中要求貨幣指示符:參閱 std::showbase |
showpoint | 為浮點數輸出無條件生成小數點字元:參閱 std::showpoint |
showpos | 為非負數輸出生成 + 字元:參閱 std::showpos |
skipws | 在某些輸入操作前跳過前導空格:參閱 std::skipws |
unitbuf | 每次輸出操作後重新整理輸出:參閱 std::unitbuf |
uppercase | 在某些輸出操作中將某些小寫字母替換為其大寫等效項:參閱 std::uppercase |
[編輯] 示例
以下示例展示了以幾種不同方式列印相同結果。
執行此程式碼
#include <iostream> int main() { const int num = 150; // using fmtflags as class member constants: std::cout.setf(std::ios_base::hex, std::ios_base::basefield); std::cout.setf(std::ios_base::showbase); std::cout << num << '\n'; // using fmtflags as inherited class member constants: std::cout.setf (std::ios::hex, std::ios::basefield); std::cout.setf (std::ios::showbase); std::cout << num << '\n'; // using fmtflags as object member constants: std::cout.setf(std::cout.hex, std::cout.basefield); std::cout.setf(std::cout.showbase); std::cout << num << '\n'; // using fmtflags as a type: std::ios_base::fmtflags ff; ff = std::cout.flags(); ff &= ~std::cout.basefield; // unset basefield bits ff |= std::cout.hex; // set hex ff |= std::cout.showbase; // set showbase std::cout.flags(ff); std::cout << num << '\n'; // not using fmtflags, but using manipulators: std::cout << std::hex << std::showbase << num << '\n'; }
輸出
0x96 0x96 0x96 0x96 0x96
[編輯] 另請參見
管理格式標誌 (公共成員函式) | |
設定特定格式標誌 (公共成員函式) | |
清除特定格式標誌 (公共成員函式) | |
更改整數 I/O 所用的基數 (函式) | |
更改填充字元 (函式模板) | |
(C++11)(C++11) |
更改浮點 I/O 所用的格式 (函式) |
控制是否使用字首指示數字基數 (函式) | |
在布林值的文字表示和數字表示之間切換 (函式) | |
控制非負數是否使用 + 符號(函式) | |
控制浮點表示中是否始終包含小數點 (函式) | |
控制每次操作後是否重新整理輸出 (函式) | |
控制輸入時是否跳過前導空白字元 (函式) | |
控制某些輸出格式是否使用大寫字元 (函式) |