Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
IOstream Library
manipulators
classes:
filebuf
fstream
ifstream
ios
iostream
ios_base
istream
istringstream
ofstream
ostream
ostringstream
streambuf
stringbuf
stringstream
objects:
cerr
cin
clog
cout
types:
fpos
streamoff
streampos
streamsize
istream
istream::istream
istream::~istream
member classes:
istream::sentry
member functions:
istream::gcount
istream::get
istream::getline
istream::ignore
istream::operator>>
istream::peek
istream::putback
istream::read
istream::readsome
istream::seekg
istream::sync
istream::tellg
istream::unget


istream::sentry

public member class
class sentry;

Perform exception safe prefix/suffix operations

This member class performs during its construction a series of operations that prepare the stream object to perform input operations.

An object of this class is automatically constructed by all member functions that perform an input operation on the stream. Formatted input operations construct the sentry object with false as the second parameter, while unformatted input operations use true for this parameter.

After being constructed, these functions evaluate the sentry object, and only continue with their input operation if true is returned.

All these member functions destruct the sentry object before returning.

The structure of this class is:
1
2
3
4
5
6
7
8
9
class istream::sentry {
public:
  explicit sentry ( istream& is, bool noskipws = false );
  ~sentry();
  operator bool() const;
private:
  sentry (const sentry&);             // not defined
  sentry& operator= (const sentry& ); // not defined
};


Members

constructor: explicit sentry ( istream& is, bool noskipws = false )
The constructor is in charge of performing the initial safety checks. Before proceeding, it checks whether none of the stream's internal error flags are set. If so, the constructor performs the appropiate operations to grant that the tied output stream is flushed in the case that the input buffer underflows.
Then, if both the parameter noskipws is false and the internal skipws flag is set, the construction extracts whitespaces from the input sequence until a non-whitespace character is encountered. If an error happens while performing these extractions both the failbit and eofbit flags will be set, and an exception may be thrown if the member ios::exceptions is set to the appropiate value.
The private declarations of the copy constructor and assignment operation without definitions prevent constructed sentry objects to be copied.
destructor: ~sentry
no operation
operator bool() const
When the object is evaluated, it returns a boolean value indicating whether the input sequence is ready.

Basic template member declaration

( basic_istream<charT,traits> )
1
2
3
4
5
6
7
8
9
10
class basic_istream<charT,traits>::sentry {
  typedef traits traits_type;
public:
  explicit sentry ( basic_istream<charT,traits>& is, bool noskipws = false );
  ~sentry ();
  operator bool() const;
private:
  sentry (const sentry&);
  sentry& operator= (const sentry&);
};