std::ends
来自 cppreference.cn
定义于头文件 <ostream> |
||
template< class CharT, class Traits > std::basic_ostream<CharT, Traits>& ends( std::basic_ostream<CharT, Traits>& os ); |
||
将空字符插入到输出序列 os 中,如同调用了 os.put(CharT())。
这是一个仅输出的 I/O 操纵器,对于任何类型为 std::basic_ostream 的 out
,它都可以通过诸如 out << std::ends 的表达式来调用。
目录 |
[编辑] 注意
此操纵器通常与 std::ostrstream 一起使用,当关联的输出缓冲区需要以空字符结尾才能作为 C 字符串处理时。
与 std::endl 不同,此操纵器不会刷新流。
[编辑] 参数
os | - | 输出流的引用 |
[编辑] 返回值
os(插入空字符后流的引用)。
[编辑] 示例
运行此代码
#include <cstdio> #include <strstream> int main() { std::ostrstream oss; oss << "Sample text: " << 42 << std::ends; std::printf("%s\n", oss.str()); oss.freeze(false); // enable memory deallocation }
输出
Sample text: 42
[编辑] 参阅
(在 C++98 中已废弃)(在 C++26 中已移除) |
实现字符数组输出操作 (类) |