CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Wed, 23 Jul 2025 17:04:34 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/istream/basic_istream/sentry/
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 23 Jul 2025 17:04:34 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"8312-/yI3qHD1JQqPOq4IY5UG20Eb0VQ"
Content-Encoding: gzip
Member class that performs a series of operations before and after each input operation:
Its constructor performs the following operations on the stream object passed as its argument (in the same order):
There are no required operations to be performed by its destructor. But implementations may use the construction and destruction of sentry objects to perform additional initialization or cleanup operations on the stream common to all input operations.
All member functions that perform an input operation automatically construct an object of this class and then evaluate it (which returns
The operator>> formatted input operations construct the sentry object by passing
The structure of this class is:
Output:
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>
<istream>
class templates
classes
manipulators
basic_istream
- basic_istream::~basic_istream
- basic_istream::basic_istream
member classes
member functions
non-member overloads
protected members
-
basic_istream::operator=C++11
-
basic_istream::swapC++11
-
- Reference
- <istream>
- basic_istream
- sentry
public member class
<istream> <iostream>
std::basic_istream::sentry
class sentry;
Prepare stream for input
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 sets its failbit flag and returns.
- If it is a tied stream, the function flushes the stream it is tied to (if its output buffer is not empty). The class may implement ways for library functions to defer this flush until the next call to overflow by its associated stream buffer.
- If its skipws format flag is set, and the constructor is not passed
true
as second argument (noskipws), all leading whitespace characters (locale-specific) are extracted and discarded. If this operation exhausts the source of characters, the function sets both the failbit and eofbit internal state flags
There are no required operations to be performed by its destructor. But implementations may use the construction and destruction of sentry objects to perform additional initialization or cleanup operations on the stream common to all input operations.
All member functions that perform an input 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 input operation (otherwise, it returns without performing it). Before returning, the function destroys the sentry object.The operator>> formatted input operations construct the sentry object by passing
false
as second argument (which skips leading whitespaces). All other member functions that construct a sentry object pass true
as second argument (which does not skip leading whitespaces).The structure of this class is:
|
|
|
|
Members
- explicit sentry (basic_istream& is, bool noskipws = false);
-
Prepares the output stream for an output operation, performing the actions described above.
- ~sentry();
- Performs no operations (implementation-defined).
- 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.
Example
|
|
Output:
digits parsed: 5552326 |
See also
- basic_istream::operator>>
- Extract formatted input (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