iostream
classes¤
ios
base class¤¤
streambuf
base class¤¤
istream
class¤
ostream
class¤
filebuf
and fstream
classes¤
stringbuf
and stringstream
classes¤
iostream
classes¤
ios
heirarchy, and the
streambuf
hierarchy¤.
ios
hierarchy¤ defines the interface¤ of the
I/O system
streambuf
hierarchy¤ defines the implementation¤
of the I/O system
ios
base class¤¤
enum iostate { goodbit, failbit, badbit, eofbit };
class ios
{
public:
ios(streambuf* sb);
virtual ~ios(void);
// HANDLING STATE
iostate rdstate(void) const;
void clear(iostate state = goodbit);
void setstate(iostate state);
// CHECKING STATE
bool good(void) const;
bool eof(void) const;
bool fail(void) const;
bool bad(void) const;
// ACCESSING BUFFER
streambuf* rdbuf(void) const;
// HANDLING FLAGS
fmtflags flags(void) const;
fmtflags setf(fmtflags fmtfl);
void unsetf(fmtflags mask);
streamsize precision(void) const;
streamsize precision(streamsize prec);
streamsize width(void) const;
streamsize width(streamsize wide);
protected:
ios(void);
class streambuf* buf;
private:
fmtflags flags;
iostate state;
streamsize width_val;
streamsize prec_val;
};
streambuf
base class¤¤
char
array)
class streambuf {
public:
virtual ~streambuf(void);
// MANIPULATE THE GET AREA
streamsize in_avail(void);
int sbumpc(void);
int sgetc(void);
streamsize sgetn(char* s, streamsize n);
int sputbackc(char c);
int sungetc(void);
// MANIPULATE THE PUT AREA
int sputc(char c);
streamsize sputn(const char* s, streamsize n);
protected:
streambuf(void);
// GET BUFFER
char* eback(void) const;
char* gptr(void) const;
char* egptr(void) const;
void gbump(int n);
void setg(char* gbeg, char* gnext, char* gend);
// PUT BUFFER
char* pbase(void) const;
char* pptr(void) const;
char* epptr(void) const;
void pbump(int n);
void setp(char* pbeg, char* pend);
virtual streambuf* setbuf(char* s, streamsize n);
// SEEKING IN A DIRECTION OR TO A POINT
virtual pos_type seekoff(off_type off, seekdir way, openmode which);
virtual pos_type seekpos(pos_type sp, openmode which);
// ACTUAL OUTPUT
virtual int sync(void);
// LOW LEVEL BUFFERIGN AND ERRORS
virtual int showmanyc(void);
virtual streamsize xsgetn(char* s, streamsize n);
virtual int underflow(void);
virtual int uflow(void);
virtual int pbackfail(int c);
virtual streamsize xsputn(const char* s, streamsize n);
virtual int overflow (int c);
private:
char* gbuf;
char* gbufnext;
char* gbufend;
char* pbuf;
char* pbufnext;
char* pbufend;
};
istream
class¤
class istream : virtual public ios {
public:
istream(streambuf* sb);
virtual ~istream(void);
// HELPER CLASS ENSURES SYNCHRONIZATION
class sentry;
// INPUT TO INBUILTS
istream& operator>>(istream& (*pf)(istream&))
istream& operator>>(ios& (*pf)(ios&))
istream& operator>>(bool& n);
istream& operator>>(short& n);
istream& operator>>(unsigned short& n);
istream& operator>>(int& n);
istream& operator>>(unsigned int& n);
istream& operator>>(long& n);
istream& operator>>(unsigned long& n);
istream& operator>>(float& f);
istream& operator>>(double& f);
istream& operator>>(long double& f);
istream& operator>>(void*& p);
istream& operator>>(streambuf* sb);
// UNFORMATTED READS
int get(void);
istream& get(char& c);
istream& get(char* s, streamsize n);
istream& get(char* s, streamsize n, char delim);
istream& getline(char* s, streamsize n);
istream& getline(char* s, streamsize n, char delim);
istream& ignore (streamsize n = 1, int delim);
// HOW LONG WAS LAST UNFORMATTED READ?
streamsize gcount(void) const;
// LOW-LEVEL OUTPUT
int peek(void);
istream& read(char* s, streamsize n);
istream& putback(char c);
istream& unget(void);
int sync(void);
pos_type tellg(void);
istream& seekg(pos_type);
istream& seekg(off_type, seekdir);
};
ostream
class¤
istream
class¤
class ostream : virtual public ios
{
public:
ostream(streambuf* sb);
virtual ~ostream();
// HELPER CLASS ENSURES SYNCHRONIZATION
class sentry;
// OUTPUT INBUILTS
ostream& operator<<(ostream& (*pf)(ostream&));
ostream& operator<<(ios& (*pf)(ios&));
ostream& operator<<(bool n);
ostream& operator<<(short n);
ostream& operator<<(unsigned short n);
ostream& operator<<(int n);
ostream& operator<<(unsigned int n);
ostream& operator<<(long n);
ostream& operator<<(unsigned long n);
ostream& operator<<(float f);
ostream& operator<<(double f);
ostream& operator<<(long double f);
ostream& operator<<(void* p);
// UNFORMATTED OUTPUT
ostream& put(char c);
// LOW-LEVEL OUTPUT
ostream& write(const char* s, streamsize n);
ostream& flush();
pos_type tellp();
ostream& seekp(pos_type);
ostream& seekp(off_type, seekdir);
};
filebuf
and fstream
classes¤
streambuf
, and a translator class¤
from istream
or ostream
class filebuf : public streambuf
{
public:
filebuf();
virtual ~filebuf();
bool is_open() const;
filebuf* open(const char* s, openmode mode);
filebuf* close();
protected:
virtual int showmanyc();
virtual int underflow();
virtual int uflow();
virtual int pbackfail(int c);
virtual int overflow (int c);
virtual streambuf* setbuf(char* s, streamsize n);
virtual pos_type seekoff(off_type off, seekdir way, openmode which);
virtual pos_type seekpos(pos_type sp, openmode which);
virtual int sync();
private:
int filedescriptor;
};
class ifstream : public istream {
public:
ifstream();
ifstream(const char* s, openmode mode);
filebuf* rdbuf() const;
bool is_open();
void open(const char* s, openmode mode);
void close();
private:
filebuf buf;
};
stringbuf
and stringstream
classes¤
stringbuf
and istringstream
classes¤
class stringbuf : public streambuf
{
public:
stringbuf(openmode which);
stringbuf(const string& str, openmode which);
string str() const;
void str(const string& s);
protected:
virtual int underflow();
virtual int pbackfail(int c);
virtual int overflow (int c);
virtual streambuf* setbuf(char*, streamsize);
virtual pos_type seekoff(off_type off, seekdir way, openmode which);
virtual pos_type seekpos(pos_type sp, openmode which);
private:
string data;
};
class istringstream : public istream
{
public:
istringstream(openmode which);
istringstream(const string& str, openmode which);
stringbuf* rdbuf() const;
string str() const;
void str(const string& s);
};