Name

basic_ios class template — Base class template for all I/O streams

Synopsis

template <class charT, class traits = char_traits<charT> >
class basic_ios : public ios_base
{
public:
  typedef charT char_type;
  typedef typename traits::int_type int_type;
  typedef typename traits::pos_type pos_type;
  typedef typename traits::off_type off_type;
  typedef traits traits_type;
  // Status
  operator void*(  );
  const bool operator!(  );
  const iostate rdstate(  ) const;
  void clear(iostate state = goodbit);
  void clear(io_state state);
  void setstate(iostate state);
  void setstate(io_state state);
  bool good(  ) const;
  bool eof(  ) const;
  bool fail(  ) const;
  bool bad(  ) const;
  iostate exceptions(  ) const;
  void exceptions(iostate except);
  void exceptions(io_state except);
  explicit basic_ios(basic_streambuf<charT,traits>* sb);
  virtual ~basic_ios(  );
  basic_ostream<charT,traits>* tie(  ) const;
  basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr);
  basic_streambuf<charT,traits>* rdbuf(  ) const;
  basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb);
  basic_ios& copyfmt(const basic_ios& rhs);
  char_type fill(  ) const;
  char_type fill(char_type ch);
  locale imbue(const locale& loc);
  char narrow(char_type c, char deflt) const;
  char_type widen(char c) const;
protected:
  basic_ios(  );
  void init(basic_streambuf<charT,traits>* buf);
private:
  basic_ios(const basic_ios& );           // Not defined
  basic_ios& operator=(const basic_ios&); // Not defined
};

The basic_ios class template is the root of all I/O stream class templates. It provides a common functionality for all derived stream classes; in particular, it manages a stream buffer. In the following descriptions, the name buf refers to a private data member that points to the stream buffer. An implementation can use any name.

The following are the member functions of basic_ios:

basic_ios ( )

The default constructor leaves the data members uninitialized. In a derived class, the default constructor must call init to initialize the members.

basic_ios (const basic_ios&)

The copy constructor is declared private and is not defined, which prevents the copying of any I/O stream objects.

explicit basic_ios (basic_streambuf<charT,traits>* sb)

Calls init(sb) to initialize the members.

operator void* ( )

If fail( ) returns true, the void* operator returns a null pointer; otherwise, it returns a non-null pointer to indicate success. operator void* is most often used as an implicit conversion in a conditional (e.g., while (cin) cin >> data[i++]).

const bool operator! ( )

Returns fail( ). operator ! is most often used in a conditional (e.g., if (!cout) cerr << "output error\n").

basic_ios& operator= (const basic_ios&)

The assignment operator, like the copy constructor, is private, so it cannot be used and is not defined. Assigning or copying an I/O stream would corrupt the stream buffer.

bool bad ( ) const

Returns true if badbit is set in rdstate( ), or false otherwise.

void clear (iostate state = goodbit), void clear (io_state state)

Sets the I/O state to state. If rdbuf( ) is a null pointer, badbit is also set (to state | ios_base::badbit). After setting the state, if any state bit is an exception bit ((rdstate( ) & exceptions( )) != 0), basic_ios::failure is thrown.

The second form is deprecated. See ios_base::iostate later in this section for details.

basic_ios& copyfmt (const basic_ios& rhs)

Copies formatting information from rhs. In particular, the format flags, fill character, locale, and the contents of the iword( ) and pword( ) arrays are copied. The I/O state and stream buffer are not copied. Before copying any callback functions, each one is called with erase_event. The callbacks are then replaced with those copied from rhs, and each one is called with copyfmt_event. (See ios_base for information about callbacks.) The exceptions( ) mask is copied last. The return value is *this.

bool eof ( ) const

Returns true if eofbit is set in rdstate( ), or false otherwise.

iostate exceptions ( ) const, void exceptions (iostate except), void exceptions (io_state except)

Returns or sets the exception mask. (See the clear function for how and when an exception is thrown.) The third form is deprecated. See ios_base::iostate later in this section for details.

bool fail ( ) const

Returns true if badbit is set or if failbit is set in rdstate( ), or false if neither bit is set.

char_type fill ( ) const, char_type fill (char_type ch)

Returns or changes the fill character (also called the pad character). When setting the fill character, the old fill character is returned.

bool good ( ) const

Returns true if the I/O state is clean—that is, it returns rdstate( ) == 0.

locale imbue (const locale& loc)

Calls ios_base::imbue(loc) and rdbuf( )->pubimbue(loc) (if rdbuf( ) is not null). The return value is the previous value of ios_base::imbue( ).

void init (basic_streambuf<charT,traits>* buf)

Initializes the basic_ios object. Table 13-12 lists the observable effects of initialization. Also, the arrays for iword( ) and pword( ) are initially null pointers.

See Also

ios_base class, ctype in <locale> , basic_streambuf in <streambuf>