std::ends
来自cppreference.com
在标头 <ostream> 定义 | ||
template<class CharT, class Traits > std::basic_ostream<CharT, Traits>& ends(std::basic_ostream<CharT, Traits>& os ); | ||
如同以调用 os.put(CharT()) 向输出序列 os
中插入空字符。
这是仅输出的 I/O 操纵符,可以用如 out << std::ends 的表达式对任何 std::basic_ostream 类型的 out
调用。
目录 |
[编辑]注解
此操纵符通常和 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);// 启用内存解分配}
输出:
Sample text: 42
[编辑]参阅
(C++98 弃用)(C++26 移除) | 实现字符数组输出操作 (类) |