The setfill() function is used in C to set the fill character of the output stream. Its usage is: std::setfill(char ch); This function fills the output value to the specified width, such as: • std: :cout << std::setfill(' ') << std::setw(10) << 3.14 << std::endl; will output: 3.14
setfill() function usage in C
setfill() function is a function provided by the
<code class="cpp">std::setfill(char ch);</code>
where ch is the padding character to be set.
Detailed Usage
The setfill() function is used to output specific characters in the output stream until the specified width is reached. This width is usually set by the setw() function. If the output value is smaller than the specified width, it is padded with the specified characters.
For example, the following code will output the decimal 3.14, padded with spaces to a width of 10:
<code class="cpp">std::cout << std::setfill(' ') << std::setw(10) << 3.14 << std::endl;</code>
This will output:
<code> 3.14</code>
Notes
The above is the detailed content of How to use setfill in c++. For more information, please follow other related articles on the PHP Chinese website!