C++ Ostream Library - sentry


Advertisements

Description

It is used to prepare stream for output. 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.

Declaration

Following is the declaration for std::basic_ostream::sentry.

C++98

class sentry {
   public:
      explicit sentry (basic_ostream& os);
      ~sentry();
      operator bool() const;
   private:
      sentry (const sentry&);
      sentry& operator= (const sentry&);
};

C++11

class sentry {
   public:
      explicit sentry (basic_ostream& os);
      ~sentry();
      explicit operator bool() const;
      sentry (const sentry&) = delete;
      sentry& operator= (const sentry&) = delete;
};

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 returns false for that object.

ostream.htm
Advertisements