Files
2025-10-25 03:02:53 +03:00

3.0 KiB
Raw Permalink Blame History

[ostream.sentry]

31 Input/output library [input.output]

31.7 Formatting and manipulators [iostream.format]

31.7.6 Output streams [output.streams]

31.7.6.2 Class template basic_ostream [ostream]

31.7.6.2.4 Class basic_ostream::sentry [ostream.sentry]

🔗

namespace std {template<class charT, class traits>class basic_ostream<charT, traits>::sentry {bool ok_; // exposition onlypublic:explicit sentry(basic_ostream& os); ~sentry(); explicit operator bool() const { return ok_; } sentry(const sentry&) = delete; sentry& operator=(const sentry&) = delete; };}

1

#

The classsentry defines a class that is responsible for doing exception safe prefix and suffix operations.

🔗

explicit sentry(basic_ostream& os);

2

#

Ifos.good() is nonzero, prepares for formatted or unformatted output.

Ifos.tie() is not a null pointer, callsos.tie()->flush().283

3

#

If, after any preparation is completed,os.good() istrue,ok_ == true otherwise,ok_ == false.

During preparation, the constructor may callsetstate(failbit) (which may throwios_base::failure ([iostate.flags])).284

🔗

~sentry();

4

#

If(os.flags() & ios_base::unitbuf) && !uncaught_exceptions()&& os.good() istrue, callsos.rdbuf()->pubsync().

If that function returns −1 or exits via an exception, sets badbit inos.rdstate() without propagating an exception.

🔗

explicit operator bool() const;

5

#

Effects: Returnsok_.

283)283)

The callos.tie()->flush() does not necessarily occur if the function can determine that no synchronization is necessary.

284)284)

Thesentry constructor and destructor can also perform additionalimplementation-dependent operations.