std::basic_ios<CharT,Traits>::fill 来自cppreference.com < cpp | io | basic ios C++ 语言 标准库头文件 自立与有宿主实现 具名要求 语言支持库 概念库 (C++20) 诊断库 工具库 字符串库 容器库 迭代器库 范围库 (C++20) 算法库 数值库 本地化库 输入/输出库 文件系统库 (C++17) 正则表达式库 (C++11) 原子操作库 (C++11) 线程支持库 (C++11) 技术规范 输入/输出库 I/O 操纵符 C 风格 I/O 缓冲 basic_streambuf basic_filebuf basic_stringbuf strstreambuf(C++98 中弃用) basic_syncbuf(C++20) 流 抽象 ios_base basic_ios basic_istream basic_ostream basic_iostream 文件 I/O basic_ifstream basic_ofstream basic_fstream 字符串 I/O basic_istringstream basic_ostringstream basic_stringstream 数组 I/O istrstream(C++98 中弃用) ostrstream(C++98 中弃用) strstream(C++98 中弃用) 同步的输出 basic_osyncstream(C++20) 类型 streamoff streamsize fpos 错误类别接口 iostream_category(C++11) io_errc(C++11) std::basic_ios 成员函数 basic_ios::basic_ios basic_ios::~basic_ios 状态函数 basic_ios::good basic_ios::eof basic_ios::fail basic_ios::bad basic_ios::operator! basic_ios::operator bool basic_ios::rdstate basic_ios::setstate basic_ios::clear 格式化 basic_ios::copyfmt basic_ios::fill 杂项 basic_ios::exceptions basic_ios::imbue basic_ios::rdbuf basic_ios::tie basic_ios::narrow basic_ios::widen 受保护成员函数 basic_ios::init basic_ios::move basic_ios::swap basic_ios::set_rdbuf CharT fill() const; (1) CharT fill( CharT ch ); (2) 管理用于填充输入转换到指定宽度的填充字符。 1) 返回当前的填充字符 2) 设置填充字符为 ch ,返回填充字符的先前值 参数 ch - 用作填充字符的字符 返回值 调用函数前的填充字符。 示例 运行此代码 #include <iostream> #include <iomanip> int main () { std::cout << "With default setting : " << std::setw(10) << 40 << '\n'; char prev = std::cout.fill('x'); std::cout << "Replaced '" << prev << "' with '" << std::cout.fill() << "': " << std::setw(10) << 40 << '\n'; } 输出: With default setting : 40 Replaced ' ' with 'x': xxxxxxxx40 参阅 setfill 更改填充字符 (函数模板)