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()函數