ostream - Member Functions and Data by Group

Constructors & Destructor

Objects of the ostream class can be constructed and destructed.

~ostream
public:virtual ~ostream()

This is supported on AIX OS/400 z/OS

Destructs an ostream object.

ostream
Overload 1
public:ostream(streambuf*)

This is supported on AIX OS/400 z/OS

This constructor takes a single argument which is a pointer to a streambuf object. This constructor creates an ostream object that is attached to the streambuf object pointed to by the argument. The format variables are initialized to their defaults.

Overload 2
public:ostream(int fd)

This is supported on AIX OS/400 z/OS

This constructor is obsolete; do not use it.

Overload 3
public:ostream(int size, char*)

This is supported on AIX OS/400 z/OS

This constructor is obsolete; do not use it.

Overload 4
protected:ostream()

This is supported on AIX OS/400 z/OS

This constructor is obsolete; do not use it.

Insertion Functions

You can use the insertion functions to insert characters into a stream buffer as a sequence of bytes.

complicated_put
public:ostream& complicated_put(char c)

This is supported on AIX OS/400 z/OS

flush
public:ostream& flush()

This is supported on AIX OS/400 z/OS

The ultimate consumer of characters that are stored in a stream buffer may not necessarily consume them immediately. flush() causes any characters that are stored in the stream buffer attached to the output stream to be consumed.

When ostream::flush() is called, one of the following occurs:

ls_complicated
Overload 1
public:ostream& ls_complicated(char)

This is supported on AIX OS/400 z/OS

Internal function. Do not use.

Overload 2
public:ostream& ls_complicated(signed char)

This is supported on AIX OS/400 z/OS

Internal function. Do not use.

Overload 3
public:ostream& ls_complicated(unsigned char)

This is supported on AIX OS/400 z/OS

Internal function. Do not use.

put
public:ostream& put(char c)

This is supported on AIX OS/400 z/OS

Inserts c into the stream buffer attached to the output stream. put() sets the error state of the output stream if the insertion fails.

write
Overload 1
public:ostream& write(const signed char* s, int n)

This is supported on AIX OS/400 z/OS

Inserts n characters that begin at the position pointed to by s. This array of characters does not need to end with a null character.

Overload 2
public:ostream& write(const char* s, int n)

This is supported on AIX OS/400 z/OS

Inserts n characters that begin at the position pointed to by s. This array of characters does not need to end with a null character.

Overload 3
public:ostream& write(const unsigned char* s, int n)

This is supported on AIX OS/400 z/OS

Inserts n characters that begin at the position pointed to by s. This array of characters does not need to end with a null character.

Output operators

The output operator calls the output prefix function opfx() before inserting characters into a stream buffer, and calls the output suffix function osfx() after inserting characters.

operator <<
Overload 1
public:ostream& operator <<(const unsigned char*)

This is supported on AIX OS/400 z/OS

The output operator inserts all the characters in the string into the stream buffer with the exception of the null character that terminates the string.

If ios::x_width is greater than zero and the representation of the value to be inserted is less than ios::x_width, the output operator inserts enough fill characters to ensure that the representation occupies an entire field in the stream buffer.

Overload 2
public:ostream& operator <<(const char*)

This is supported on AIX OS/400 z/OS

The output operator inserts all the characters in the string into the stream buffer with the exception of the null character that terminates the string.

If ios::x_width is greater than zero and the representation of the value to be inserted is less that ios::x_width, the output operator inserts enough fill characters to ensure that the representation occupies an entire field in the stream buffer.

Overload 3
public:ostream& operator <<(const void*)

This is supported on AIX OS/400 z/OS

The output operator converts pointers to void to integral values and then converts them to hexadecimal values as if ios::showbase were set. This version of the output operator is used to print out the values of pointers.

Overload 4
public:ostream& operator <<(ios & ( * f ) ( ios & ))

This is supported on AIX OS/400 z/OS

The following built-in manipulators are accepted by this output operator:

       ios&   dec(ios&)
       ios&   hex(ios&)
       ios&   oct(ios&)

These manipulators have a specific effect on an ostream object beyond inserting their own values. For example, If outs is a reference to an ostream object, then this statement sets ios::dec:

       outs << dec;
Overload 5
public:ostream& operator <<(unsigned char c)

This is supported on AIX OS/400 z/OS

The output operator inserts the character into the stream buffer without performing any conversion on it.

Overload 6
public:ostream& operator <<(unsigned long)

This is supported on AIX OS/400 z/OS

The output operator converts the integral value according to the format state of the output stream and inserts characters into the stream buffer associated with the output stream. There is no overflow detection on conversion of integral types.

The conversion that takes place depends, in part, on the settings of the following format flags:

  • If ios::oct is set, the integral type is converted to a series of octal digits. If ios::showbase is set, "0" is inserted into the stream buffer before the octal digits. If the value being inserted is equal to 0, a single "0" is inserted, not "00".
  • If ios::dec is set, the integral type is converted to a series of decimal digits.
  • If ios::hex is set, the integral type is converted to a series of hexadecimal digits. If ios::showbase is set, "0x" (or "0X" if ios::uppercase is set) is inserted into the stream buffer before the hexadecimal digits.

If none of these format flags is set, the integral type is converted to a series of decimal digits. Then its sign also affects the conversion:

  • If the integral type is negative, a negative sign "-" is inserted before the decimal digits
  • If the integral type is equal to 0, the single digit 0 is inserted
  • If the integral type is positive and ios::showpos is set, a positive sign "+" is inserted before the decimal digits.
Overload 7
public:ostream& operator <<(long long)

This is supported on AIX OS/400 z/OS

The output operator converts the integral value according to the format state of the output stream and inserts characters into the stream buffer associated with the output stream. There is no overflow detection on conversion of integral types.

The conversion that takes place depends, in part, on the settings of the following format flags:

  • If ios::oct is set, the integral type is converted to a series of octal digits. If ios::showbase is set, "0" is inserted into the stream buffer before the octal digits. If the value being inserted is equal to 0, a single "0" is inserted, not "00".
  • If ios::dec is set, the integral type is converted to a series of decimal digits.
  • If ios::hex is set, the integral type is converted to a series of hexadecimal digits. If ios::showbase is set, "0x" (or "0X" if ios::uppercase is set) is inserted into the stream buffer before the hexadecimal digits.

If none of these format flags is set, the integral type is converted to a series of decimal digits. Then its sign also affects the conversion:

  • If the integral type is negative, a negative sign "-" is inserted before the decimal digits
  • If the integral type is equal to 0, the single digit 0 is inserted
  • If the integral type is positive and ios::showpos is set, a positive sign "+" is inserted before the decimal digits.

Note: The support for long long is controlled by _LONG_LONG, __EXTENDED__, or the -q(no)longlong option.

Overload 8
public:ostream& operator <<(unsigned int a)

This is supported on AIX OS/400 z/OS

The output operator converts the integral value according to the format state of the output stream and inserts characters into the stream buffer associated with the output stream. There is no overflow detection on conversion of integral types.

The conversion that takes place depends, in part, on the settings of the following format flags:

  • If ios::oct is set, the integral type is converted to a series of octal digits. If ios::showbase is set, "0" is inserted into the stream buffer before the octal digits. If the value being inserted is equal to 0, a single "0" is inserted, not "00".
  • If ios::dec is set, the integral type is converted to a series of decimal digits.
  • If ios::hex is set, the integral type is converted to a series of hexadecimal digits. If ios::showbase is set, "0x" (or "0X" if ios::uppercase is set) is inserted into the stream buffer before the hexadecimal digits.

If none of these format flags is set, the integral type is converted to a series of decimal digits. Then its sign also affects the conversion:

  • If the integral type is negative, a negative sign "-" is inserted before the decimal digits
  • If the integral type is equal to 0, the single digit 0 is inserted
  • If the integral type is positive and ios::showpos is set, a positive sign "+" is inserted before the decimal digits.
Overload 9
public:ostream& operator <<(double)

This is supported on AIX OS/400 z/OS

The output operator performs a conversion operation on the argument and inserts it into the stream buffer attached to the output stream. The conversion depends on the values returned by the following functions:

  • precision() - returns the number of significant digits that appear after the decimal. The default value is 6.
  • width() - if this returns 0, the argument is inserted without any fill characters. If the return value is greater than the number of characters needed to represent the argument, extra fill characters are inserted so that the total number of characters inserted is equal to the return value.

The conversion also depends on the values of the following format flags:

  • If ios::scientific is set, the argument is converted to scientific notation with one digit before the decimal, and the number of digits after the decimal equal to the value returned by precision(). The exponent begins with a lowercase "e" unless ios::uppercase is set, in which case the exponent begins with an uppercase "E".
  • If ios::fixed is set, the argument is converted to fixed notation, with the number of digits after the decimal point equal to the value returned by precision().
  • If neither ios::fixed nor ios::scientific is set, the conversion depends upon the value of the argument. If ios::uppercase is set, the exponents of values in scientific notation begin with an uppercase "E".
Overload 10
public:ostream& operator <<(short i)

This is supported on AIX OS/400 z/OS

The output operator converts the integral value according to the format state of the output stream and inserts characters into the stream buffer associated with the output stream. There is no overflow detection on conversion of integral types.

The conversion that takes place depends, in part, on the settings of the following format flags:

  • If ios::oct is set, the integral type is converted to a series of octal digits. If ios::showbase is set, "0" is inserted into the stream buffer before the octal digits. If the value being inserted is equal to 0, a single "0" is inserted, not "00".
  • If ios::dec is set, the integral type is converted to a series of decimal digits.
  • If ios::hex is set, the integral type is converted to a series of hexadecimal digits. If ios::showbase is set, "0x" (or "0X" if ios::uppercase is set) is inserted into the stream buffer before the hexadecimal digits.

If none of these format flags is set, the integral type is converted to a series of decimal digits. Then its sign also affects the conversion:

  • If the integral type is negative, a negative sign "-" is inserted before the decimal digits
  • If the integral type is equal to 0, the single digit 0 is inserted
  • If the integral type is positive and ios::showpos is set, a positive sign "+" is inserted before the decimal digits.
Overload 11
public:ostream& operator <<(long double)

This is supported on AIX OS/400 z/OS

The output operator performs a conversion operation on the argument and inserts it into the stream buffer attached to the output stream. The conversion depends on the values returned by the following functions:

  • precision() - returns the number of significant digits that appear after the decimal. The default value is 6.
  • width() - if this returns 0, the argument is inserted without any fill characters. If the return value is greater than the number of characters needed to represent the argument, extra fill characters are inserted so that the total number of characters inserted is equal to the return value.

The conversion also depends on the values of the following format flags:

  • If ios::scientific is set, the argument is converted to scientific notation with one digit before the decimal, and the number of digits after the decimal equal to the value returned by precision(). The exponent begins with a lowercase "e" unless ios::uppercase is set, in which case the exponent begins with an uppercase "E".
  • If ios::fixed is set, the argument is converted to fixed notation, with the number of digits after the decimal point equal to the value returned by precision().
  • If neither ios::fixed nor ios::scientific is set, the conversion depends upon the value of the argument. If ios::uppercase is set, the exponents of values in scientific notation begin with an uppercase "E".
Overload 12
public:ostream& operator <<(int a)

This is supported on AIX OS/400 z/OS

The output operator converts the integral value according to the format state of the output stream and inserts characters into the stream buffer associated with the output stream. There is no overflow detection on conversion of integral types.

The conversion that takes place depends, in part, on the settings of the following format flags:

  • If ios::oct is set, the integral type is converted to a series of octal digits. If ios::showbase is set, "0" is inserted into the stream buffer before the octal digits. If the value being inserted is equal to 0, a single "0" is inserted, not "00".
  • If ios::dec is set, the integral type is converted to a series of decimal digits.
  • If ios::hex is set, the integral type is converted to a series of hexadecimal digits. If ios::showbase is set, "0x" (or "0X" if ios::uppercase is set) is inserted into the stream buffer before the hexadecimal digits.

If none of these format flags is set, the integral type is converted to a series of decimal digits. Then its sign also affects the conversion:

  • If the integral type is negative, a negative sign "-" is inserted before the decimal digits
  • If the integral type is equal to 0, the single digit 0 is inserted
  • If the integral type is positive and ios::showpos is set, a positive sign "+" is inserted before the decimal digits.
Overload 13
public:ostream& operator <<(long)

This is supported on AIX OS/400 z/OS

The output operator converts the integral value according to the format state of the output stream and inserts characters into the stream buffer associated with the output stream. There is no overflow detection on conversion of integral types.

The conversion that takes place depends, in part, on the settings of the following format flags:

  • If ios::oct is set, the integral type is converted to a series of octal digits. If ios::showbase is set, "0" is inserted into the stream buffer before the octal digits. If the value being inserted is equal to 0, a single "0" is inserted, not "00".
  • If ios::dec is set, the integral type is converted to a series of decimal digits.
  • If ios::hex is set, the integral type is converted to a series of hexadecimal digits. If ios::showbase is set, "0x" (or "0X" if ios::uppercase is set) is inserted into the stream buffer before the hexadecimal digits.

If none of these format flags is set, the integral type is converted to a series of decimal digits. Then its sign also affects the conversion:

  • If the integral type is negative, a negative sign "-" is inserted before the decimal digits
  • If the integral type is equal to 0, the single digit 0 is inserted
  • If the integral type is positive and ios::showpos is set, a positive sign "+" is inserted before the decimal digits.
Overload 14
public:ostream& operator <<(unsigned long long)

This is supported on AIX OS/400 z/OS

The output operator converts the integral value according to the format state of the output stream and inserts characters into the stream buffer associated with the output stream. There is no overflow detection on conversion of integral types.

The conversion that takes place depends, in part, on the settings of the following format flags:

  • If ios::oct is set, the integral type is converted to a series of octal digits. If ios::showbase is set, "0" is inserted into the stream buffer before the octal digits. If the value being inserted is equal to 0, a single "0" is inserted, not "00".
  • If ios::dec is set, the integral type is converted to a series of decimal digits
  • If ios::hex is set, the integral type is converted to a series of hexadecimal digits. If ios::showbase is set, "0x" (or "0X" if ios::uppercase is set) is inserted into the stream buffer before the hexadecimal digits.

If none of these format flags is set, the integral type is converted to a series of decimal digits. Then its sign also affects the conversion:

  • If the integral type is negative, a negative sign "-" is inserted before the decimal digits
  • If the integral type is equal to 0, the single digit 0 is inserted
  • If the integral type is positive and ios::showpos is set, a positive sign "+" is inserted before the decimal digits.

Note: The support for long long is controlled by _LONG_LONG, __EXTENDED__, or the -q(no)longlong option.

Overload 15
public:ostream& operator <<(unsigned short i)

This is supported on AIX OS/400 z/OS

The output operator converts the integral value according to the format state of the output stream and inserts characters into the stream buffer associated with the output stream. There is no overflow detection on conversion of integral types.

The conversion that takes place depends, in part, on the settings of the following format flags:

  • If ios::oct is set, the integral type is converted to a series of octal digits. If ios::showbase is set, "0" is inserted into the stream buffer before the octal digits. If the value being inserted is equal to 0, a single "0" is inserted, not "00".
  • If ios::dec is set, the integral type is converted to a series of decimal digits.
  • If ios::hex is set, the integral type is converted to a series of hexadecimal digits. If ios::showbase is set, "0x" (or "0X" if ios::uppercase is set) is inserted into the stream buffer before the hexadecimal digits.

If none of these format flags is set, the integral type is converted to a series of decimal digits. Then its sign also affects the conversion:

  • If the integral type is negative, a negative sign "-" is inserted before the decimal digits
  • If the integral type is equal to 0, the single digit 0 is inserted
  • If the integral type is positive and ios::showpos is set, a positive sign "+" is inserted before the decimal digits.
Overload 16
public:ostream& operator <<(const wchar_t*)

This is supported on AIX OS/400 z/OS

The output operator converts the wchar_t string to its equivalent multibyte character string, and then inserts it into the stream buffer with the exception of the null character that terminates the string.

If ios::x_width is greater than zero and the representation of the value to be inserted is less than ios::x_width, the output operator inserts enough fill characters to ensure that the representation occupies an entire field in the stream buffer.

Overload 17
public:ostream& operator <<(signed char c)

This is supported on AIX OS/400 z/OS

The output operator inserts the character into the stream buffer without performing any conversion on it.

Overload 18
public:ostream& operator <<(float)

This is supported on AIX OS/400 z/OS

The output operator performs a conversion operation on the argument and inserts it into the stream buffer attached to the output stream. The conversion depends on the values returned by the following functions:

  • precision() - returns the number of significant digits that appear after the decimal. The default value is 6.
  • width() - if this returns 0, the argument is inserted without any fill characters. If the return value is greater than the number of characters needed to represent the argument, extra fill characters are inserted so that the total number of characters inserted is equal to the return value.

The conversion also depends on the values of the following format flags:

  • If ios::scientific is set, the argument is converted to scientific notation with one digit before the decimal, and the number of digits after the decimal equal to the value returned by precision(). The exponent begins with a lowercase "e" unless ios::uppercase is set, in which case the exponent begins with an uppercase "E".
  • If ios::fixed is set, the argument is converted to fixed notation, with the number of digits after the decimal point equal to the value returned by precision().
  • If neither ios::fixed nor ios::scientific is set, the conversion depends upon the value of the argument. If ios::uppercase is set, the exponents of values in scientific notation begin with an uppercase "E".
Overload 19
public:ostream& operator <<(ostream & ( * f ) ( ostream & ))

This is supported on AIX OS/400 z/OS

The following built-in manipulators are accepted by this output operator:

       ostream&   endl(ostream&)
       ostream&   ends(ostream&)
       ostream&   flush(ostream&)

These manipulators have a specific effect on an ostream object beyond inserting their own values. For example, If outs is a reference to an ostream object, then this statement inserts a newline character and calls flush():

       outs << endl;

This statement inserts a null character:

       outs << ends;

This statement flushes the stream buffer attached to outs. It is equivalent to flush():

       outs << flush;
Overload 20
public:ostream& operator <<(wchar_t)

This is supported on AIX OS/400 z/OS

The output operator inserts the character into the stream buffer without performing any conversion on it.

Overload 21
public:ostream& operator <<(streambuf*)

This is supported on AIX OS/400 z/OS

If opfx() returns a nonzero value, the output operator inserts all of the characters that can be taken from the streambuf pointer into the stream buffer attached to the output stream. Insertion stops when no more characters can be fetched from the streambuf. No padding is performed.

Overload 22
public:ostream& operator <<(const signed char*)

This is supported on AIX OS/400 z/OS

The output operator inserts all the characters in the string into the stream buffer with the exception of the null character that terminates the string.

If ios::x_width is greater than zero and the representation of the value to be inserted is less than ios::x_width, the output operator inserts enough fill characters to ensure that the representation occupies an entire field in the stream buffer.

Overload 23
public:ostream& operator <<(char c)

This is supported on AIX OS/400 z/OS

The output operator inserts the character into the stream buffer without performing any conversion on it.

Positioning Functions

seekp

Functions that work with the put pointer of the ultimate consumer.

Overload 1
public:ostream& seekp(streampos p)

This is supported on AIX OS/400 z/OS

Repositions the put pointer of the ultimate consumer. Sets the put pointer to the position p.

Overload 2
public:ostream& seekp(streamoff o, ios::seek_dir d)

This is supported on AIX OS/400 z/OS

Repositions the put pointer of the ultimate consumer. Sets the put pointer to the position specified by d with the offset of o. The seek dir, d, can have the following values:

  • ios::beg - the beginning of the stream
  • ios::cur - the current position of the put pointer
  • ios::end - the end of the stream

The new position of the put pointer is equal to the position specified by d offset by the value o. If you attempt to move the put pointer to a position that is not valid, seekp() sets ios::badbit.

tellp
public:streampos tellp()

This is supported on AIX OS/400 z/OS

Returns the current position of the put pointer of the stream buffer that is attached to the output stream.

Prefix and Suffix Functions

Functions that are called either before or after inserting characters into the ultimate consumer.

opfx
public:int opfx()

This is supported on AIX OS/400 z/OS

opfx() is called by the output operator before inserting characters into a stream buffer. opfx() checks the error state of the output stream. If the internal flag ios::hardfail is set, opfx() returns 0. Otherwise, opfx() flushes the stream buffer attached to the ios object pointed to by tie(), if one exists, and returns the value returned by ios::good(). ios::good() returns 0 if ios::failbit, ios::badbit, or ios:eofbit is set. Otherwise, ios::good() returns a nonzero value.

osfx
public:void osfx()

This is supported on AIX OS/400 z/OS

osfx() is called before a formatted output function returns. osfx() flushes the streambuf object attached to the output stream if ios::unitbuf is set.

osfx() is called by the output operator. If you overload the output operator to handle your own classes, you should ensure that osfx() is called after any direct manipulation of a streambuf object. Binary output functions do not call osfx().

do_opfx
protected:int do_opfx()

This is supported on AIX OS/400 z/OS

Internal function. Do not use.

do_osfx
protected:void do_osfx()

This is supported on AIX OS/400 z/OS

Internal function. Do not use.