basic_ostream
·
flush
·
operator<<
·
opfx
·
osfx
·
put
·
seekp
·
sentry
·
tellp
·
write
template <class E, class T = char_traits<E> >
class basic_ostream {
public:
class sentry;
explicit basic_ostream(basic_streambuf<E, T> *sb);
virtual ~ostream();
bool opfx();
void osfx();
basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
basic_ostream& operator<<(basic_ios<E, T>& (*pf)(basic_ios<E, T>&));
basic_ostream& operator<<(ios_base<E, T>& (*pf)(ios_base<E, T>&));
basic_ostream& operator<<(basic_streambuf<E, T> *sb);
basic_ostream& operator<<(const char *s);
basic_ostream& operator<<(char c);
basic_ostream& operator<<(bool n);
basic_ostream& operator<<(short n);
basic_ostream& operator<<(unsigned short n);
basic_ostream& operator<<(int n);
basic_ostream& operator<<(unsigned int n);
basic_ostream& operator<<(long n);
basic_ostream& operator<<(unsigned long n);
basic_ostream& operator<<(float n);
basic_ostream& operator<<(double n);
basic_ostream& operator<<(long double n);
basic_ostream& operator<<(void * n);
basic_ostream& put(E c);
basic_ostream& write(E *s, streamsize n);
basic_ostream& flush();
pos_type tellp();
basic_ostream& seekp(pos_type pos);
basic_ostream& seekp(off_type off, ios_base::seek_dir way);
};
The template class describes an object that controls insertion of elements and encoded objects into a stream buffer with
elements of type E
, whose character traits are determined by the class T
.
Most of the member functions that overload operator<<
are formatted output functions. They follow the pattern:
iostate state = goodbit;
const sentry ok(*this);
if (ok)
{try
{convert and insert elements
accumulate flags in state}
catch (...)
{if (exceptions() & badbit)
throw;
setstate(badbit); }}
width(0); // except for operator<<(E)
setstate(state);
return (*this);
Two other member functions are unformatted output functions. They follow the pattern:
iostate state = goodbit;
const sentry ok(*this);
if (!ok)
state |= badbit;
else
{try
{obtain and insert elements
accumulate flags in state}
catch (...)
{if (rdstate() & badbit)
throw;
setstate(badbit); }}
setstate(state);
return (*this);
Both groups of functions call setstate
(badbit)
if they encounter a failure while inserting elements.
An object of class basic_ostream<E, T>
stores only a virtual public base object of class basic_ios
<E, T>
.