std::setfill
时间: 2023-10-23 09:08:40 浏览: 99
std::setfill is a manipulator function in C++ that sets the fill character for output streams. It is used in conjunction with other output formatting functions like std::setw to specify the character that should be used to fill the empty spaces when values are printed with fixed width.
Here is an example of how std::setfill can be used:
```cpp
#include <iostream>
#include <iomanip>
int main() {
int number = 123;
std::cout << "Default fill: " << std::setw(10) << number << std::endl;
std::cout << "Set fill to '-': " << std::setfill('-') << std::setw(10) << number << std::endl;
std::cout << "Set fill to '*': " << std::setfill('*') << std::setw(10) << number << std::endl;
return 0;
}
```
Output:
```
Default fill: 123
Set fill to '-': ----123
Set fill to '*': *******123
```
In the example, std::setfill('-') and std::setfill('*') are used to set the fill character to '-' and '*', respectively. The std::setw(10) sets the width of the output to 10 characters.
阅读全文