std::setfill
来自 cppreference.cn
定义于头文件 <iomanip> |
||
template< class CharT > /*unspecified*/ setfill( CharT c ); |
||
在表达式 out << setfill(c) 中使用时,将流 out 的填充字符设置为 c。
内容 |
[编辑] 参数
c | - | 填充字符的新值 |
[编辑] 返回值
未指定类型的对象,使得
- 如果 out 是类型为 std::basic_ostream<CharT, Traits> 的对象,则表达式 out << setfill(c)
- 具有类型 std::basic_ostream<CharT, Traits>&
- 具有值 out
- 行为如同调用 f(out, c)
其中函数 f 定义为
template<class CharT, class Traits> void f(std::basic_ios<CharT, Traits>& str, CharT c) { // set fill character str.fill(c); }
[编辑] 注解
当前的填充字符可以使用 std::ostream::fill 获取。
[编辑] 示例
运行此代码
输出
default fill: [ 42] setfill('*'): [********42]
[编辑] 缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。
DR | 应用于 | 发布时的行为 | 正确的行为 |
---|---|---|---|
LWG 183 | C++98 | setbase 只能用于类型为 std::ostream 的流 |
可用于任何输出 字符流 |
[编辑] 参见
管理填充字符 ( std::basic_ios<CharT,Traits> 的公共成员函数) | |
设置填充字符的位置 (函数) | |
更改下一个输入/输出字段的宽度 (函数) |