Namespaces
Variants

std:: setfill

From cppreference.net
< cpp ‎ | io ‎ | manip
ヘッダーで定義 <iomanip>
template < class CharT >
/*unspecified*/ setfill ( CharT c ) ;

式内で使用された場合 out << setfill ( c ) はストリーム out のフィル文字を c に設定します。

目次

パラメータ

c - フィル文字の新しい値

戻り値

未指定の型のオブジェクトであり、以下の条件を満たすもの:

  • out が型 std:: basic_ostream < CharT, Traits > のオブジェクトである場合、式 out << setfill ( c ) は:
    • std:: basic_ostream < CharT, Traits > & を持つ
    • out を持つ
    • f ( out, c ) を呼び出したかのように振る舞う

関数 f が以下のように定義されている場合:

template<class CharT, class Traits>
void f(std::basic_ios<CharT, Traits>& str, CharT c)
{
    // フィル文字を設定
    str.fill(c);
}

注記

現在の埋め文字は std::ostream::fill で取得できます。

#include <iomanip>
#include <iostream>
int main()
{
    std::cout << "default fill: [" << std::setw(10) << 42 << "]\n"
              << "setfill('*'): [" << std::setfill('*')
                                   << std::setw(10) << 42 << "]\n";
}

出力:

default fill: [        42]
setfill('*'): [********42]

不具合報告

以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。

DR 適用対象 公開時の動作 正しい動作
LWG 183 C++98 setbase std::ostream 型の
ストリームでのみ使用可能
任意の出力文字ストリームで
使用可能

関連項目

フィル文字を管理する
( std::basic_ios<CharT,Traits> の公開メンバ関数)
フィル文字の配置を設定する
(関数)
次の入出力フィールドの幅を変更する
(関数)