# std::ends

> C++ Atlas: `cppatlas.com/w/cpp/io/manip/ends` | Source: https://en.cppreference.com/w/cpp/io/manip/ends | Domain: Input/output | Standards: C++98, C++26

Inserts a null character into the output sequence os as if by calling os.put(CharT()).

## Official Specification Summary (cppreference)

```cpp
// Defined in header <ostream>

template< class CharT, class Traits >
std::basic_ostream<CharT, Traits>& ends( std::basic_ostream<CharT, Traits>& os );
```

Inserts a null character into the output sequence `os` as if by calling `os.put(CharT())`.

This is an output-only I/O manipulator, it may be called with an expression such as `out << std::ends` for any `out` of type `std::basic_ostream`.

### Notes

This manipulator is typically used with `std::ostrstream`, when the associated output buffer needs to be null-terminated to be processed as a C string.

Unlike `std::endl`, this manipulator does not flush the stream.

### Parameters

- `os` - reference to output stream

### Return value

`os` (reference to the stream after insertion of the null character).

### Example

```cpp
#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
}
```

Output:

```text
Sample text: 42
```

### See also

- [`ostrstream`](https://en.cppreference.com/w/cpp/io/ostrstream) (deprecated in C++98): implements character array output operations (class)

---
Attribution: content from https://en.cppreference.com/w/cpp/io/manip/ends (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.