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 操纵符,可以与诸如 out << std::ends 的表达式一同调用,其中 out
的类型为 std::basic_ostream。
内容 |
[编辑] 注解
此操纵符通常与 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 中移除) |
实现字符数组输出操作 (类) |