std::setfill()函数

C++函数std::setfill 的行为就像在流上调用c作为参数的成员填充,它作为操纵器插入(它可以插入到输出流上)。

它用于将c设置为流的填充字符。

声明

以下是std::setfill函数的声明。

setfill (char_type c);

参数

  • c − 流的新填充字符。char_type是流使用的字符类型(即,它的第一个类模板参数charT)。

返回值

它返回unspecified,此函数应仅用作流操纵器。

示例

下面的例子解释了 setfill 函数的用法。

#include <iostream>
#include <iomanip>

int main () {
   std::cout << std::setfill ('y') << std::setw (10);
   std::cout << 77 << std::endl;
   return 0;
}

编译和运行上面的程序,将产生以下结果 -

yyyyyyyy77

上一篇: std::setbases()函数 下一篇: std::setprecision()函数