This is a summary of the C++ Stream Input/Output Libraries // The include files are in // /usr/local/lib/g++-include iostream.h -- normal Input/Output iomanip.h -- Manipulating formats and such fstream.h -- accessing files strstream.h -- treating strings as files // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. ------------------------iostreams.h-------------------------------- extern char* form(const char*, ...); //Use printf formating on ... items For NUMERIC=long|int|unsigned|long unsigned, extern char* dec(NUMERIC, int=0);// decimal format of ints,longs,.... extern char* hex(NUMERIC, int=0);// octal format extern char* oct(NUMERIC, int=0);// hex format extern char* oct(int, int=0); extern char* oct(unsigned long, int=0); extern char* oct(unsigned int, int=0); char* chr(char ch, int width = 0); //Convert char to string char* str(const char* s, int width = 0);// Format string to width class istream; class ostream;// Inout and output streams extern istream& ws(istream& ins);//?? extern ostream& flush();// flush cout extern ostream& flush(ostream& outs);// send bufferout... extern ostream& endl(ostream& outs);//mark end of line extern ostream& ends(ostream& outs);//Mark end of stream(close it) Output Character: ostream& put(char c)// output a character to this stream ostream& put(unsigned char c) // output a character to this stream ostream& put(signed char c) { return put((char)c); } Output various types of data: ostream& operator<<(char c); ostream& operator<<(unsigned char c); ostream& operator<<(signed char c) ; ostream& operator<<(const char *s); ostream& operator<<(const unsigned char *s) ostream& operator<<(const signed char *s) ostream& operator<<(const void *p); ostream& operator<<(int n); ostream& operator<<(unsigned int n); ostream& operator<<(long n); ostream& operator<<(unsigned long n); ostream& operator<<(long long n); ostream& operator<<(unsigned long long n); ostream& operator<<(short n) ostream& operator<<(unsigned short n) ostream& operator<<(double n); ostream& operator<<(float n) ostream& operator<<(__omanip func) ostream& operator<<(__manip func) ostream& operator<<(streambuf*) Input functions Input character istream& get(char* ptr, int len, char delim = '\n'); istream& get(unsigned char* ptr, int len, char delim = '\n') istream& get(char& c); istream& get(signed char& c) { return get((char&)c); } istream& get(signed char* ptr, int len, char delim = '\n') istream& get(unsigned char& c) { return get((char&)c); } Input string with delimeter and max length istream& getline(char* ptr, int len, char delim = '\n'); istream& getline(unsigned char* ptr, int len, char delim = '\n') istream& getline(signed char* ptr, int len, char delim = '\n') istream& read(char *ptr, int n); istream& read(unsigned char *ptr, int n) { return read((char*)ptr, n); } istream& read(signed char *ptr, int n) { return read((char*)ptr, n); } istream& read(void *ptr, int n) { return read((char*)ptr, n); } istream& get(streambuf& sb, char delim = '\n');//does not skip whitespace istream& gets(char **s, char delim = '\n');//UNSAFE and INSECURE! istream& scan(const char *format ...);//The old scanf rides again Undo Input istream& unget(char ch) { return putback(ch); } Ignore input chars int skip(int i); streambuf* istreambuf() const ; istream& operator>>(char*);//UNSAFE unless you set width to space allocated in string istream& operator>>(unsigned char* p) { return operator>>((char*)p); } istream& operator>>(signed char*p) { return operator>>((char*)p); } istream& operator>>(char& c);// skips whitespace unless you unset skipws istream& operator>>(unsigned char& c) {return operator>>((char&)c);} istream& operator>>(signed char& c) {return operator>>((char&)c);} istream& operator>>(int&); istream& operator>>(long&); istream& operator>>(unsigned long long&); istream& operator>>(short&); istream& operator>>(unsigned int&); istream& operator>>(unsigned long&); istream& operator>>(unsigned short&); istream& operator>>(double&); istream& operator>>(streambuf*); class iostream : public istream, public ostream{...}; Standard Input and output streams extern istream cin; extern ostream cout, cerr, clog; Control base of output and input ios& dec(ios& i)//set decimal output ios& hex(ios& i)//set hexadecimal output ios& oct(ios& i)//set octal outpu State of a stream: GOOD -- nothing has gone wrong yet FAIL -- something didn't work but the stream is OK BAD -- this stream has gone wrong EOF -- there is no more data to read here (unless FAIL occurred) Functions that extract state of stream int rdstate()//bit pattern describing state of stream Functions that test for exceptional conditions int good() const // True when GOOD int eof() const //False if input has failed int fail() const // true if failed state OR bad state int bad() const The easiest way to read to EOF is to attempt to input characters and test for success at the same time while( cin >> character ) .... because if the input fails th stream fails the test(it is (void*)0) resetting after Failing ios& clear()// set state to good ios& clear(states)//sets states ---------------ios member functions and constants----- Functions that change formatting Note: Some functions are also manipulators with different names. For example output_stream << setiosflags(whatever) is like output_stream.setf(whatever) and output_stream << resetiosflags(whatever) is like output_stream.unsetf(whatever) fill(int);//fill character (default is space) width(int);//width limit on field (input and output) setf(flags);//set falgs to be true unsetf(flags);//set flags to false setf(selection,ingroup);//set to selection List of flags and groups ios::flag ios::group Meaning left adjustfield left alignment right adjustfield right alignment internal adjustfield sign on the left, remainder right dec basefield decimals hex " hexadecimal oct " Octal showbase showpos Show +sign on positive uppercase EXABCDEF not exabcdef fixed floatfield fixed form of floating point scientific floatfield force exponential format showpoint show point at end for whole numbers ----------------iomanip.h------------------------- Input and Output Manipulators This library automatically #includes Manipulators are used in one of two ways: input_stream >> input_manipulator output_stream << output_manipulator Note: Some manipulators are also implemented as functions with with different names. For example output_stream << setiosflags(whatever) is like output_stream.setf(whatever) and output_stream << resetiosflags(whatever) is like output_stream.unsetf(whatever) // Available Manipulators setbase( int ) // base used to represent number setfill( int ) // Character used to fill non-digits in number setprecision( int ) //How many decimals after the point setw( int ) //How many characters for the data resetiosflags( ios::fmtflags ) // reset various properties setiosflags( ios::fmtflags ) // set various properties ------formatting flags----- These always have ios:: in front of them. The following some of the ones in the library. dec use decimals fixed no exponentials hex use hexadecimals internal ?? left left justified oct use octal right right justified scientific sceintific notation showbase Show base (hex,octal,...) showpoint Always show a point showpos ?? skipws Skip whitespace on input stdio ?? unitbuf ?? uppercase ?? ------------------------fstream.h------------ class fstreambase : virtual public ios { public: fstreambase(); fstreambase(int fd); fstreambase(const char *name, int mode, int prot=0664); void close(); filebuf* rdbuf() const ; void open(const char *name, int mode, int prot=0664); int is_open() const ; void setbuf(char *ptr, int len) ; }; class ifstream : public fstreambase, public istream { public: ifstream() : fstreambase() { } ifstream(int fd) : fstreambase(fd) { } ifstream(const char *name, int mode=ios::in, int prot=0664) : fstreambase(name, mode, prot) { } void open(const char *name, int mode=ios::in, int prot=0664); }; class ofstream : public fstreambase, public ostream { public: ofstream() : fstreambase() { } ofstream(int fd) : fstreambase(fd) { } ofstream(const char *name, int mode=ios::out, int prot=0664) : fstreambase(name, mode, prot) { } void open(const char *name, int mode=ios::out, int prot=0664) ; }; class fstream : public fstreambase, public iostream { public: fstream() : fstreambase() { } fstream(int fd) : fstreambase(fd) { } fstream(const char *name, int mode, int prot=0664) : fstreambase(name, mode, prot) { } void open(const char *name, int mode, int prot=0664) ; }; ------------------------strstream.h---------- #include class strstreambuf : public backupbuf { //private and protected stuff public: virtual ~strstreambuf(); strstreambuf() ; strstreambuf(int initial_size) ; strstreambuf(void *(*alloc)(_G_size_t), void (*free)(void*)) ; strstreambuf(char *ptr, int size, char *pstart = NULL) ; strstreambuf(unsigned char *ptr, int size, unsigned char *pstart = NULL) ; strstreambuf(const char *ptr, int size) ; strstreambuf(const unsigned char *ptr, int size) ; int frozen() ; void freeze(int n=1) ; _G_size_t pcount(); char *str(); virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out); }; class strstreambase : virtual public ios { public: strstreambuf* rdbuf() ; //hidden stuff }; class istrstream : public strstreambase, public istream { public: istrstream(const char*, int=0); }; class ostrstream : public strstreambase, public ostream { public: ostrstream(); ostrstream(char *cp, int n, int mode=ios::out) :strstreambase(cp,n,mode){} _G_size_t pcount() ; char *str() ; void freeze(int n = 1) ; int frozen() ; }; class strstream : public strstreambase, public iostream { public: strstream() : strstreambase() ; strstream(char *cp, int n, int mode=ios::out) :strstreambase(cp,n,mode){} _G_size_t pcount() ; char *str() ; void freeze(int n = 1) ; int frozen() ; };