CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Thu, 24 Jul 2025 14:09:03 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/ostream/basic_ostream/sentry/
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 24 Jul 2025 14:09:03 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"76b4-qbCl3+T05Zh1Blht8lS5HLtOZds"
Content-Encoding: gzip
Member class that performs a series of operations before and after each output operation:
Its constructor performs the following operations on the stream object passed as its argument (in the same order):
Its destructor performs the following operations on the same stream object (in the same order):
Implementations may use the construction and destruction of sentry objects to perform additional initialization or cleanup operations on the stream common to all output operations.
All member functions that perform an output operation automatically construct an object of this class and then evaluate it (which returns
The structure of this class is:
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
basic_ostream
- basic_ostream::~basic_ostream
- basic_ostream::basic_ostream
member classes
member functions
non-member overloads
protected members
-
basic_ostream::operator=C++11
-
basic_ostream::swapC++11
-
- Reference
- <ostream>
- basic_ostream
- sentry
public member class
<ostream> <iostream>
std::basic_ostream::sentry
class sentry;
Prepare stream for output
Its constructor performs the following operations on the stream object passed as its argument (in the same order):
- If any of its internal error flags is set, the function may set its failbit flag and return.
- If it is a tied stream, the function flushes the stream it is tied to (if its output buffer is not empty), unless the function determines that synchronization is not necessary.
On failure, it may set the failbit flag.
Its destructor performs the following operations on the same stream object (in the same order):
-
If the unitbuf format flag is set, and there are no uncaught exceptions, the function flushes the stream (as if calling
rdbuf()->pubsync()
).
If the unitbuf format flag is set, and neither there are uncaught exceptions nor any internal error flag is set, the function flushes the stream (by callingrdbuf()->pubsync()
).
If this call to pubsync returns-1
, the badbit is set without propagating an exception (even if member exceptions has this flag set).
Implementations may use the construction and destruction of sentry objects to perform additional initialization or cleanup operations on the stream common to all output operations.
All member functions that perform an output operation automatically construct an object of this class and then evaluate it (which returns
true
if no state flag was set). Only if this object evaluates to true
, the function attempts the output operation (otherwise, it returns without performing it). Before returning, the function destroys the sentry object.The structure of this class is:
|
|
|
|
Members
- explicit sentry (basic_ostream& os);
-
Prepares the output stream for an output operation, performing the actions described above.
- ~sentry();
-
Performs the operations described above.
- explicit operator bool() const;
- When the object is evaluated, it returns a
bool
value indicating whether the sentry constructor successfully performed all its tasks: If at some point of the construction process, an internal error flags was set, this function always returnsfalse
for that object.
See also
- basic_ostream::operator<<
- Insert formatted output (public member function)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us