---
name: "std::basic_ostream_sentry"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/std::basic_ostream_sentry"
---

# std::basic\_ostream\_sentry(3)

Performs setup work for output streams.

## NAME

std::basic\_ostream\< \_CharT, \_Traits \>::sentry - Performs setup work for output streams.

## SYNOPSIS

\#include \<ostream\>

### Public Member Functions

**sentry** (**basic\_ostream**\< \_CharT, \_Traits \> &\_\_os)\
 The constructor performs preparatory work.  **~sentry** ()\
 Possibly flushes the stream.  **operator bool** () const\
 Quick status checking.

## Detailed Description

### template\<typename \_CharT, typename \_Traits\>

class std::basic\_ostream\< \_CharT, \_Traits \>::sentry"Performs setup work for output streams.

Objects of this class are created before all of the standard inserters are run. It is responsible for *exception-safe prefix and suffix operations*.

## Constructor & Destructor Documentation

### template\<typename \_CharT, typename \_Traits\> std::basic\_ostream\< \_CharT, \_Traits \>::sentry::sentry (basic\_ostream\< \_CharT, \_Traits \> & \_\_os) \[explicit\]

The constructor performs preparatory work.

**Parameters**

*\_\_os* The output stream to guard.

If the stream state is good (*\_\_os.good()* is true), then if the stream is tied to another output stream, is.tie()-\>flush() is called to synchronize the output sequences.

If the stream state is still good, then the sentry state becomes true (*okay*).

References **std::basic\_ostream\< \_CharT, \_Traits \>::basic\_ostream()**, **std::basic\_ios\< \_CharT, \_Traits \>::bad()**, **std::ios\_base::failbit**, **std::basic\_ios\< \_CharT, \_Traits \>::good()**, **std::basic\_ios\< \_CharT, \_Traits \>::setstate()**, and **std::basic\_ios\< \_CharT, \_Traits \>::tie()**.

### template\<typename \_CharT, typename \_Traits\> std::basic\_ostream\< \_CharT, \_Traits \>::sentry::~sentry () \[inline\]

Possibly flushes the stream. If ios\_base::unitbuf is set in os.flags(), and std::uncaught\_exception() is true, the sentry destructor flushes the output stream.

References **std::ios\_base::badbit**, **std::uncaught\_exception()**, and **std::ios\_base::unitbuf**.

## Member Function Documentation

### template\<typename \_CharT, typename \_Traits\> std::basic\_ostream\< \_CharT, \_Traits \>::sentry::operator bool () const \[inline\], \[explicit\]

Quick status checking.

**Returns**

The sentry state.

For ease of use, sentries may be converted to booleans. The return value is that of the sentry state (true == okay).

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
