名前空間
変種
操作

std::ios_base::fmtflags

提供: cppreference.com
< cpp‎ | io‎ | ios base
 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
typedef /*implementation defined*/ fmtflags;
static constexpr fmtflags dec = /*implementation defined*/

static constexpr fmtflags oct = /*implementation defined*/
static constexpr fmtflags hex = /*implementation defined*/

static constexpr fmtflags basefield = dec | oct | hex;
static constexpr fmtflags left = /*implementation defined*/

static constexpr fmtflags right = /*implementation defined*/
static constexpr fmtflags internal = /*implementation defined*/

static constexpr fmtflags adjustfield = left | right | internal;
static constexpr fmtflags scientific = /*implementation defined*/

static constexpr fmtflags fixed = /*implementation defined*/

static constexpr fmtflags floatfield = scientific | fixed;
static constexpr fmtflags boolalpha = /*implementation defined*/

static constexpr fmtflags showbase = /*implementation defined*/
static constexpr fmtflags showpoint = /*implementation defined*/
static constexpr fmtflags showpos = /*implementation defined*/
static constexpr fmtflags skipws = /*implementation defined*/
static constexpr fmtflags unitbuf = /*implementation defined*/

static constexpr fmtflags uppercase = /*implementation defined*/

利用可能な書式フラグを規定します。 これは BitmaskType です。 以下の定数が定義されます。

定数 説明
dec 整数の入出力に対して10進数を使用します。 std::dec を参照してください
oct 整数の入出力に対して8進数を使用します。 std::oct を参照してください
hex 整数の入出力に対して16進数を使用します。 std::hex を参照してください
basefield dec|oct|hex。 マスク操作に便利です
left 左詰め (フィル文字を右に追加します)。 std::left を参照してください
right 右詰め (フィル文字を左に追加します)。 std::right を参照してください
internal 内部詰め (フィル文字を内部の指定された位置に追加します)。 std::internal を参照してください
adjustfield left|right|internal。 マスク操作に便利です
scientific 科学表記を使用して浮動小数点型を生成します (fixed と組み合わせた場合は16進表記)。 std::scientific を参照してください
fixed 固定表記を使用して浮動小数点型を生成します (scientific と組み合わせた場合は16進表記)。 std::fixed を参照してください
floatfield scientific|fixed。 マスク操作に便利です
boolalpha bool 型をアルファベット形式で挿入および抽出します。 std::boolalpha を参照してください
showbase 整数の出力に対して数値の基数を表す接頭辞を生成し、金額の入出力に対して金額指示子を要求します。 std::showbase を参照してください
showpoint 浮動小数点数の出力に対して小数点を無条件に生成します。 std::showpoint を参照してください
showpos 非負の数値の出力に対して + 文字を出力します。 std::showpos を参照してください
skipws 特定の入力操作の前に先行するホワイトスペースをスキップします。 std::skipws を参照してください
unitbuf 各出力操作の後に出力をフラッシュします。 std::unitbuf を参照してください
uppercase 特定の出力操作で特定の小文字を同等な大文字に置き換えます。 std::uppercase を参照してください

[編集]

以下の例は同じ結果を表示するいくつかの異なる方法を示します。

#include <iostream>
 
int main() 
{
    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

[編集] 関連項目

書式フラグを管理します
(パブリックメンバ関数) [edit]
特定の書式フラグをセットします
(パブリックメンバ関数) [edit]
特定の書式フラグをクリアします
(パブリックメンバ関数) [edit]
整数の入出力に使用される基数を変更します
(関数) [edit]
フィル文字を変更します
(関数テンプレート) [edit]
浮動小数点の入出力に使用される書式を変更します
(関数) [edit]
数値の基数を表すために接頭辞を使用するかどうか制御します
(関数) [edit]
ブーリアンの表現をテキストと数値の間で切り替えます
(関数) [edit]
非負の数値で + 記号を使用するかどうか制御します
(関数) [edit]
浮動小数点の表現に常に小数点が含まれるかどうか制御します
(関数) [edit]
各操作ごとに出力をフラッシュするかどうか制御します
(関数) [edit]
入力時に先行するホワイトスペースをスキップするかどうか制御します
(関数) [edit]
いくつかの出力書式で大文字を使用するかどうか制御します
(関数) [edit]