*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->IRIX man pages -> c++/ostream (3)              
Title
Content
Arch
Section
 

Contents


OSTREAM(3C++)							 OSTREAM(3C++)


NAME    [Toc]    [Back]

     ostream - formatted and unformatted output

SYNOPSIS    [Toc]    [Back]

     #include <iostream.h>

     typedef long streamoff, streampos;
     class ios {
     public:
	       enum	 seek_dir { beg, cur, end };
	       enum	 open_mode { in, out, ate, app,	trunc, nocreate, noreplace } ;
	       enum	 { skipws=01,
			   left=02,  right=04, internal=010,
			   dec=020, oct=040, hex=0100,
			   showbase=0200, showpoint=0400, uppercase=01000, showpos=02000,
			   scientific=04000, fixed=010000,
			   unitbuf=020000, stdio=040000	};
	       // and lots of other stuff, see ios(3C++) ...
     } ;

     class ostream : public ios	{
     public:
			 ostream(streambuf*);
	       ostream&	 flush();
	       int	 opfx();
	       ostream&	 put(char);
	       ostream&	 seekp(streampos);
	       ostream&	 seekp(streamoff, seek_dir);
	       streampos tellp();
	       ostream&	 write(const char* ptr,	int n);
	       ostream&	 write(const unsigned char* ptr, int n);
	       ostream&	 operator<<(const char*);
	       ostream&	 operator<<(char);
	       ostream&	 operator<<(short);
	       ostream&	 operator<<(int);
	       ostream&	 operator<<(long);
	       ostream&	 operator<<(float);
	       ostream&	 operator<<(double);
	       ostream&	 operator<<(unsigned char);
	       ostream&	 operator<<(unsigned short);
	       ostream&	 operator<<(unsigned int);
	       ostream&	 operator<<(unsigned long);
	       ostream&	 operator<<(void*);
	       ostream&	 operator<<(streambuf*);
	       ostream&	 operator<<(ostream& (*)(ostream&));
	       ostream&	 operator<<(ios& (*)(ios&));
     };

     class ostream_withassign {
			 ostream_withassign();
	       istream&	 operator=(istream&);
	       istream&	 operator=(streambuf*);



									Page 1






OSTREAM(3C++)							 OSTREAM(3C++)



     };

     extern ostream_withassign cout;
     extern ostream_withassign cerr;
     extern ostream_withassign clog;

     ostream&  endl(ostream&) ;
     ostream&  ends(ostream&) ;
     ostream&  flush(ostream&) ;
     ios&      dec(ios&) ;
     ios&      hex(ios&) ;
     ios&      oct(ios&) ;

DESCRIPTION    [Toc]    [Back]

     ostreams support insertion	(storing) into a streambuf.  These are
     commonly referred to as output operations.	 The ostream member functions
     and related functions are described below.

     In	the following descriptions, assume:
     - outs is an ostream.
     - outswa is an ostream_withassign.
     - outsp is	an ostream*.
     - c is a char.
     - ptr is a	char* or unsigned char*.
     - sb is a streambuf*
     - i and n are ints.
     - pos is a	streampos.
     - off is a	streamoff.
     - dir is a	seek_dir.
     - manip is	a function with	type ostream& (*)(ostream&).

   Constructors	and assignment:
	  ostream(sb<b>)
	       Initializes ios state variables and associates buffer sb	with
	       the ostream.

	  ostream_withassign()
	       Does no initialization.	This allows a file static variable of
	       this type (cout,	for example) to	be used	before it is
	       constructed, provided it	is assigned to first.

	  outswa<b>=sb
	       Associates sb with swa and initializes the entire state of
	       outswa.

	  inswa<b>=ins
	       Associates ins<b>->rdbuf() with swa	and initializes	the entire
	       state of	outswa.

   Output prefix function:





									Page 2






OSTREAM(3C++)							 OSTREAM(3C++)



	  i<b>=outs<b>.opfx()
	       If outs's error state is	nonzero, returns immediately.  If
	       outs<b>.tie() is non-null, it is flushed.  Returns non-zero	except
	       when outs's error state is nonzero.

   Output suffix function:
	  osfx()
	       Performs	``suffix'' actions before returning from inserters.
	       If ios::unitbuf is set, osfx() flushes the ostream.  If
	       ios::stdio is set, osfx() flushes stdout	and stderr.

	  osfx() is called by all predefined inserters,	and should be called
	  by user-defined inserters as well, after any direct manipulation of
	  the streambuf.  It is	not called by the binary output	functions.

   Formatted output functions (inserters):
	  outs<b><<x
	       First calls outs<b>.opfx() and if that returns 0, does nothing.
	       Otherwise inserts a sequence of characters representing x into
	       outs<b>.rdbuf().  Errors are indicated by setting the error	state
	       of outs.	 outs is always	returned.

	       x is converted into a sequence of characters (its
	       representation) according to rules that depend on x's type and
	       outs's format state flags and variables (see ios(3C++)).
	       Inserters are defined for the following types, with conversion
	       rules as	described below:

	       char*
		    The	representation is the sequence of characters up	to
		    (but not including)	the terminating	null of	the string x
		    points at.

	       any integral type except	char and <b>unsigned char
		    If x is positive the representation	contains a sequence of
		    decimal, octal, or hexadecimal digits with no leading
		    zeros according to whether ios::dec, ios::oct, or
		    ios::hex, respectively, is set in ios's format flags.  If
		    none of those flags	are set, conversion defaults to
		    decimal.  If x is zero, the	representation is a single
		    zero character(0).	If x is	negative, decimal conversion
		    converts it	to a minus sign	(-) followed by	decimal
		    digits.  If	x is positive and ios::showpos is set, decimal
		    conversion converts	it to a	plus sign (+) followed by
		    decimal digits.  The other conversions treat all values as
		    unsigned.  If ios::showbase	is set in ios's	format flags,
		    the	hexadecimal representation contains 0x before the
		    hexadecimal	digits,	or 0X if ios::uppercase	is set.	 If
		    ios::showbase is set, the octal representation contains a
		    leading 0.





									Page 3






OSTREAM(3C++)							 OSTREAM(3C++)



	       void*
		    Pointers are converted to integral values and then
		    converted to hexadecimal numbers as	if ios::showbase were
		    set.

	       float, double
		    The	arguments are converted	according to the current
		    values of outs<b>.precision(),	outs<b>.width() and outs's	format
		    flags ios::scientific, ios::fixed, and ios::uppercase.
		    (See ios(3C++).)  The default value	for outs<b>.precision()
		    is 6.  If neither ios::scientific nor ios::fixed is	set,
		    either fixed or scientific notation	is chosen for the
		    representation, depending on the value of x.

	       char, unsigned char
		    No special conversion is necessary.

	       After the representation	is determined, padding occurs.	If
	       outs<b>.width() is greater than 0 and the representation contains
	       fewer than outs<b>.width() characters, then	enough outs<b>.fill()
	       characters are added to bring the total number of characters to
	       ios.width().  If	ios::left is set in ios's format flags,	the
	       sequence	is left-adjusted, that is, characters are added	after
	       the characters determined above.	 If ios::right is set, the
	       padding is added	before the characters determined above.	 If
	       ios::internal is	set, the padding is added after	any leading
	       sign or base indication and before the characters that
	       represent the value.  ios.width() is reset to 0,	but all	other
	       format variables	are unchanged.	The resulting sequence
	       (padding	plus representation) is	inserted into outs<b>.rdbuf().

	  outs<b><<sb
	       If outs<b>.opfx() returns non-zero,	the sequence of	characters
	       that can	be fetched from	sb are inserted	into outs<b>.rdbuf().
	       Insertion stops when no more characters can be fetched from sb.
	       No padding is performed.	 Always	returns	outs.

   Unformatted output functions:
	  outsp<b>=&outs<b>.put(c)
	       Inserts c into outs<b>.rdbuf().  Sets the error state if the
	       insertion fails.

	  outsp<b>=&outs<b>.write(s<b>,n<b>)
	       Inserts the n characters	starting at s into outs<b>.rdbuf().
	       These characters	may include zeros (i.e., s need	not be a null
	       terminated string).

   Other member	functions:
	  outsp<b>=&outs<b>.flush()
	       Storing characters into a streambuf does	not always cause them
	       to be consumed (e.g., written to	the external file)
	       immediately.  flush() causes any	characters that	may have been



									Page 4






OSTREAM(3C++)							 OSTREAM(3C++)



	       stored but not yet consumed to be consumed by calling
	       outs<b>.rdbuf()->sync.

	  outs<b><<manip
	       Equivalent to manip(outs<b>).  Syntactically this looks like an
	       insertion operation, but	semantically it	does an	arbitrary
	       operation rather	than converting	manip to a sequence of
	       characters as do	the insertion operators.  Predefined
	       manipulators are	described below.

   Positioning functions:
	  outsp<b>=&ins<b>.seekp(off<b>,dir<b>)
	       Repositions outs<b>.rdbuf()'s put pointer.	See sbuf.pub(3C++) for
	       a discussion of positioning.

	  outsp<b>=&outs<b>.seekp(pos<b>)
	       Repositions outs<b>.rdbuf()'s put pointer.	See sbuf.pub(3C++) for
	       a discussion of positioning.

	  pos<b>=outs<b>.tellp()
	       The current position of outs<b>.rdbuf()'s put pointer.  See
	       sbuf.pub(3C++) for a discussion of positioning.

   Manipulators:
	  outs<b><<endl
	       Ends a line by inserting	a newline character and	flushing.

	  outs<b><<ends
	       Ends a string by	inserting a null (0) character.

	  outs<b><<flush
	       Flushes outs.

	  outs<b><<dec
	       Sets the	conversion base	format flag to 10.  See	ios(3C++).

	  outs<b><<hex
	       Sets the	conversion base	format flag to 16.  See	ios(3C++).

	  outs<b><<oct
	       Sets the	conversion base	format flag to 8.  See ios(3C++).

SEE ALSO    [Toc]    [Back]

      
      
     ios(3C++),	sbuf.pub(3C++),	manip(3C++)


									PPPPaaaaggggeeee 5555
[ Back ]
 Similar pages
Name OS Title
istream IRIX formatted and unformatted input
printf OpenBSD formatted output
printf FreeBSD formatted output
vasprintf FreeBSD formatted output conversion
snprintf OpenBSD formatted output conversion
vasprintf OpenBSD formatted output conversion
printf NetBSD formatted output conversion
sprintf OpenBSD formatted output conversion
asprintf NetBSD formatted output conversion
snprintf NetBSD formatted output conversion
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service