Namespaces
Variants

std::basic_ios<CharT,Traits>:: fill

From cppreference.net
CharT fill ( ) const ;
(1)
CharT fill ( CharT ch ) ;
(2)

管理用于将输出转换填充至指定字段宽度的填充字符。

1) 返回当前填充字符。
2) 将填充字符设置为 ch ,返回填充字符的先前值。

目录

参数

ch - 用作填充字符的字符

返回值

函数调用前的填充字符。

示例

#include <iomanip>
#include <iostream>
int main ()
{
    std::cout << "With default setting : [" << std::setw(10) << 40 << "]\n";
    char prev = std::cout.fill('x');
    std::cout << "Replaced '" << prev << "' with '"
              << std::cout.fill() << "': [" << std::setw(10) << 40 << "]\n";
}

输出:

With default setting : [        40]
Replaced ' ' with 'x': [xxxxxxxx40]

参见

修改填充字符
(函数模板)